Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show drop down list below EditText?

I have a EditText and one Button for Search, now i want to show list of search result below EditText when click on button,

enter image description here

when i enter text "abc" and click on search button then drop down should be open below EditText.

need suggestion or sample demo or code.

Edit: It should open drop down which seems like in AutoCompleteTextView

like image 806
Jayesh Avatar asked Feb 17 '23 11:02

Jayesh


2 Answers

use AutocompleteTextView, set high treshold "setTreshold()" and call showDropDown() on button click

code update:

String[] values = {
    "abc_0", "def_0", "ghi_0",
    "abc_1", "def_1", "ghi_1",
    "abc_2", "def_2", "ghi_2",
    "abc_3", "def_3", "ghi_3",
};

final AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.actv);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    android.R.layout.simple_dropdown_item_1line, values);
actv.setAdapter(adapter);
actv.setThreshold(256); // if not enough set Integer.MAX_VALUE
findViewById(R.id.button).setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        CharSequence constraint = actv.getText();
        adapter.getFilter().filter(constraint);
        actv.showDropDown();
    }
});
like image 99
pskink Avatar answered Feb 27 '23 08:02

pskink


you can call ListView or Spinner on click of search button.. and set values to its adapter...

like image 25
Mahaveer Muttha Avatar answered Feb 27 '23 08:02

Mahaveer Muttha