1

When I fill name and select in auto-complete text-view. It's not working same spinner. function in if-else not working or condition incorrect(I don't know).Please suggest me how to use onitemselectlistener on auto-complete text-view to use function in each condition.

    AutoCompleteTextView auto1 = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);

    String[] word;
    word = getResources().getStringArray(R.array.word_name);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, word);
    auto1.setAdapter(adapter);

    auto1.setOnItemSelectedListener(new OnItemSelectedListener() {
        TextView txt1 = (TextView)findViewById(R.id.textView1);
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if(arg2==0)  // when I fill AED(array 0 in string.xml It's not work)
            {  
                getmoney();
            }
            else if(arg2==1)
            {
                getmoney1();
            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {

        }
    });

String.xml

 <string-array name="word_name">
    <item>AED United Arab Emirates Dirham</item>
    <item>AFN Afghan Afghani</item>
    <item>ALL Albanian Lek</item>
    <item>AMD Armenian Dram</item>
 </string-array>
eltabo
  • 3,749
  • 1
  • 21
  • 33
Flyzy Dev
  • 91
  • 1
  • 3
  • 10
  • possible duplicate of [AutoCompleteTextView onItemSelectedListener does not work](http://stackoverflow.com/questions/9249919/autocompletetextview-onitemselectedlistener-does-not-work) – eltabo Feb 14 '14 at 08:34

1 Answers1

1

Instead of OnItemSelectedListener, OnItemClickListener works for AutocompleteTextView.

For example:

 auto1.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            Toast.makeText(MainActivity.this,
                    adapter.getItem(position).toString(),
                    Toast.LENGTH_SHORT).show();
        }
    });
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • Thank you I have question. I use if to select array but It's select array from autocomplete textview not from item in string-array(String.xml) suggest me please. – Flyzy Dev Feb 14 '14 at 09:12
  • `It's select array from autocomplete textview not from item in string-array(String.xml)` => Think on this question again, answer lies inside your question itself. – Paresh Mayani Feb 14 '14 at 09:14