forum

Home / DeveloperSection / Forums / Show DropDown onCreate not working in android

Show DropDown onCreate not working in android

Anonymous User222807-Nov-2014
So I have an autocomplete view which shows a drop down when I type... But I want the dropdown to be shown when the avtivity starts. So I found this answer which says that using showDropDown() should work. And it does work in my case when called on any TouchListener or any other user triggered event. But it doesn't work if I directly just use it in onCreate()... The following code in my onCreate() works

final AutoCompleteTextView actv = (AutoCompleteTextView)findViewById(R.id.autoCompleteUserName);
    String[] users = getResources().getStringArray(R.array.users);
    ArrayAdapter<?> adapter = new ArrayAdapter<Object>(this,R.layout.compose_ac_list_item,users);
    actv.setAdapter(adapter);
 
    actv.setOnTouchListener(new View.OnTouchListener(){
 
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // WORKS IF USED ON TOUCH
            actv.showDropDown();
              returnfalse;
        }
    });

And the following doesn't work

final AutoCompleteTextView actv = (AutoCompleteTextView)findViewById(R.id.autoCompleteUserName);
            String[] users = getResources().getStringArray(R.array.users);
            ArrayAdapter<?> adapter = new ArrayAdapter<Object>(this,R.layout.compose_ac_list_item,users);
            actv.setAdapter(adapter);
 actv.showDropDown();


Updated on 07-Nov-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By