隐藏Listview直到开始搜索 [英] Hiding Listview until search is initiated
问题描述
我有一个问题: 我有一个列表视图(来自自定义适配器),其顶部有一个搜索栏.一切正常,我唯一需要做的就是打开活动以使列表视图保持隐藏或不可见,直到在搜索栏中开始搜索为止(换句话说,使列表视图保持隐藏,直到我开始在搜索栏中输入内容为止).
I have a question: I have a listview (from custom adapter) with a searchbar on top of it. Everything works ok, the only thing I need is when opening the activity to keep the listview hidden, or invisible, until the search has started in the searchbar (in other words, to keep the listview hidden until I start typing something in the searchbar).
您可以在此处找到代码:
You can find the code here:
再加上一个建议的解决方案,不幸的是,该解决方案不起作用,您可以在此处查看:
Plus a suggested solution, which unfortunately did not work, you can see here:
我期待着您的答复,并在此先感谢您.
I am looking forward to your replies guys and I thank you in advance.
推荐答案
尝试将TextWatcher
添加到搜索EditText
中.这将检测您何时在搜索中键入内容:
Try adding TextWatcher
to your search EditText
. This will detect when you type something in your search:
EditText search= (EditText) findViewById(R.id.search);
search.addTextChangedListener(filterTextWatcher);
TextWatcher方法:
TextWatcher method:
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) {
}
};
这篇关于隐藏Listview直到开始搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!