//Listview adapter
adapter_q = new ArrayAdapter<String>(Authors.this, R.layout.list_item_author,R.id.product_name, Quotes);
lv.setAdapter(adapter_q);
//textViewq=(MultiAutoCompleteTextView)findViewById(R.layout.list_item_author);
System.out.println("before printing");
// filtering text
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
Authors.this.adapter_q.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
}
});
从列表中选择所选项目并将其发送到edittext框
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg01, View arg11, int arg21, long arg31) {
valc= arg01.getItemAtPosition(arg21).toString();
System.out.println(valc);
inputSearch.setText(valc);
}
});
这是我的搜索编辑文本框,我在其中获取值并且正确过滤, 但我的问题是,当我从列表视图中选择一个值时,列表视图仍然存在,
当我从列表视图中获取值时,如何解除它?
答案 0 :(得分:1)
假设Quotes
是你传递给适配器的字符串的arraylist,你需要执行以下操作:
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg01, View arg11, int arg21, long arg31) {
System.out.println(Quotes.get(arg21));
inputSearch.setText(Quotes.get(arg21));
}
});
因为您要显示的数据存储在数组列表中。