-2

我想在edittext中搜索联系人。但是edittext不显示联系人列表,请告诉我如何匹配电话号码以进行edittext搜索和显示。

    String products[]={};
   @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
   Bundle savedInstanceState) {
mInflater = inflater;
    View view = inflater.inflate(R.layout.contacts_list, container, false);
   contactsList = (ListView) view.findViewById(R.id.contactsList);
     inputSearch=(EditText) view.findViewById(R.id.inputSearch);

    adapter = new ArrayAdapter<String>(getActivity(), R.layout.listitem,           R.id.product_name, products);
    contactsList.setAdapter(adapter);       

   (this,android.R.layout.select_dialog_item,str));

    inputSearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3)

        {
            ContactsFragment.this.adapter.getFilter().filter(cs);

                }
            }  
        } 
    });

    return view;
}
4

1 回答 1

1

您可以使用 AutoCompleteTextView 而不是 EditText 作为休闲方式-

   AutoCompleteTextView inputSearch=(AutoCompleteTextView) view.findViewById(R.id.inputSearch);
   products = new String[]{"Product1","product2","product3"}; 
   inputSearch.setAdapter(new ArrayAdapter<String>(getActivity(),R.layout.listitem,products));
    inputSearch.setThreshold(1);
    inputSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            inputSearch.showDropDown();
        }
    });

    inputSearch.setOnItemClickListener(new OnItemClickListener(){

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
        //Do whatever you want with selected object
        }
      }

尝试这个。

于 2013-10-24T08:31:22.017 回答