AutocompleteTextView with TextWatcher

BSBS2 1 Reputation point
2021-03-09T09:24:15.763+00:00

I am trying to add TextWatcher to AutoCompleteTextView. In Activity I have Extends with Android.Text.ITextWatcher and implement interface methods. The problem is that, String helperString is not changing. I also added autocomplete.AddTextChangedListener(this); to AutoCompleteTextView. What am i doing wrong?

public void AfterTextChanged(IEditable s)
        {
            helperText = this.FindViewById<TextView>(Resource.Id.helper_text);
            String helperString = s.ToString().ToUpper();
            Console.WriteLine(helperString + "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            helperText.Text = (s.ToString().ToUpper());

        }

        public void BeforeTextChanged(Java.Lang.ICharSequence s, int start, int count, int after)
        {
            throw new NotImplementedException();
        }

        public void OnTextChanged(Java.Lang.ICharSequence s, int start, int before, int count)
        {
            String inputValue = s.ToString();
            Toast.MakeText(this, inputValue, ToastLength.Short).Show();
        }
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,369 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. cristopheB 551 Reputation points
    2021-03-09T11:11:20.217+00:00
    0 comments No comments

  2. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-03-10T05:47:44.427+00:00

    Hello,

    Welcome to Microsoft Q&A!

    Stop Setting text on AutoCompleteTextView in ITextWatcher interface , it will trigger the method (AfterTextChanged , BeforeTextChanged , OnTextChanged ) So this will lead to a infinite loop .

    If you just want uppercase words when inputing , just need to set android:inputType="textCapCharacters" on AutoCompleteTextView in xml .


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.