質問

I have a MultiAutoCompleteTextView and when you click on an item in my list of AutoComplete words, it is inserting the word I want correctly, however, when I click on the word I want to insert, I want to move my cursor to a different position than the end of the edittext's text. How can I set a listener for my adapter? My code is as follows:

    setContentView(R.layout.activity_main);
    String[] suggestions = getResources().getStringArray(R.array.list_of_suggestions);
    ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,suggestions);
    MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView)findViewById(R.id.code_text);
    textView.addTextChangedListener(mTextEditorWatcher);
    textView.setAdapter(adapter);
    textView.setTokenizer(new SColonTokenizer());

I can't set it in my text changed listener as this is called every time the user enters a character. How can I listen for an onClick on my array adapter? I know it is possible to do this using a ListView, but my suggestions are handled by the adapter and not making use of a listView to do this.

After clicking, I want to move the cursor inside the parenthesis, I know how to do this using

textView.setSelection(textView.getText().length());

just I am unsure how to call this after clicking on an array adapter item screen shot

役に立ちましたか?

解決

You can use OnItemClickListener like

textView.setOnItemClickListener(new OnItemClickListener()
{

     @Override
     public void onItemClick(AdapterView<?> parent, View view, int position, long id)           
     {
      textView.setSelection(textView.getText().length());
     }
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top