如何在ListView的搜索功能中设置文本

时间:2014-02-27 07:48:29

标签: java android listview

我在listview中创建inputsearch,并且在打开时我在inputsearch中创建了settext。我在输入搜索字段中设置了一个单词,但它可以通过我设置的单词进行搜索。它必须是类型,因为在inputsearch字段中有过滤我们键入的单词。也许有人帮我如何在没有过滤器的情况下在inputsearch字段中设置文本,当我打开我的listview时,我的listview将自动显示我在inputsearch字段中设置的单词的值。抱歉我的英文不好,谢谢你们。

enter image description here

 protected void onPostExecute(String file_url) {
        pDialog.dismiss();
        runOnUiThread(new Runnable() {
             public void run() {
                 DatabaseHandler db = new DatabaseHandler(getApplicationContext());

                /**
                 * Hashmap to load data from the Sqlite database
                 **/
                 HashMap<String,String> user = new HashMap<String, String>();
                 user = db.getUserDetails();
                 inputSearch = (EditText) findViewById(R.id.inputSearch);
                   inputSearch.setText(user.get("fname"),TextView.BufferType.EDITABLE);

                 adapter = new SimpleAdapter(
                        semuatempat.this, data_map,
                        R.layout.list_item, new String[] { tanya_nama, tanya_judul, tanya_komen,tanya_jawaban,tanya_waktu}, 
                        new int[] {R.id.nama, R.id.alamat, R.id.lat,R.id.lng,R.id.waktu});
                setListAdapter(adapter);

            }
        });

        // selecting single ListView item
          ListView lv = getListView();


          inputSearch.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3)  {
                    // When user changed the Text
                   semuatempat.this.adapter.getFilter().filter(cs); 

                }

                @Override
                public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                        int arg3) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void afterTextChanged(Editable arg0) {
                    // TODO Auto-generated method stub                         
                }
            });

0 个答案:

没有答案