我有一个问题:我有一个列表视图(来自自定义适配器),上面有一个搜索栏。一切正常,唯一需要的是打开活动以保持列表视图隐藏或不可见,直到搜索在搜索栏中开始(换句话说,直到我开始在搜索栏中键入某些内容时,列表视图才被隐藏)。
您可以在这里找到代码:
另外还有一个建议的解决方案,不幸的是,它没有起作用,您可以在这里看到:
我期待着你们的回复,伙计们,我提前感谢你们。
发布于 2015-11-16 20:31:10
尝试将TextWatcher
添加到搜索EditText
中。当您在搜索中键入某些内容时,这将检测到:
EditText search= (EditText) findViewById(R.id.search);
search.addTextChangedListener(filterTextWatcher);
TextWatcher方法:
private TextWatcher filterTextWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
//Change the visibility here
list.setVisibility(View.VISIBLE);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
};
发布于 2015-11-16 18:35:27
我想你可能在想一个AutoCompleteTextView?它要求您将列表数据加载到其适配器中,然后设置适配器。
// Get a reference to the AutoCompleteTextView in the layout
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
// Get the string array
String[] countries = getResources().getStringArray(R.array.countries_array);
// Create the adapter and set it to the AutoCompleteTextView
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);
textView.setAdapter(adapter);
谷歌指南:这里。
https://stackoverflow.com/questions/33748155
复制