Question

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>
Was it helpful?

Solution

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();
        }
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top