在autoCompleteTextView上使用setAdapter方法在从android中的listView中搜索列表项时会是正确的吗?

时间:2016-06-24 10:51:09

标签: android listview autocompletetextview

我使用listView实现了使用autoCompleteTextView搜索项目的代码。代码如下:

public class SearchActivity extends Activity {
    ArrayAdapter<String> myAdapter;
    ListView listView;
    String[] dataArray = new String[] {"India","America", "Russia", "China", "Nepal", "Japan"};
    private AutoCompleteTextView actv;  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
        listView = (ListView) findViewById(R.id.listview);
        myAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, dataArray);
        listView.setAdapter(myAdapter);
        listView.setTextFilterEnabled(true);
        actv.setAdapter(myAdapter);
        actv.setThreshold(1);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {   
        @Override
         public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        }
       });
    }
}

0 个答案:

没有答案