Android的搜索列表默认情况下不可见的?能不能做到? [英] Android search list invisible by default? Can it be done?
问题描述
喜家伙我有一个问题:
总之,我有一个列表视图,以在它顶部的搜索栏,我也能过滤结果等之后,开始我的其他活动;基本上一切工作正常和甜蜜。
In short, I have a listview, with a searchbar on top of it, I am also able to start my other activities after filtering the results etc; basically everything works fine and sweet.
我的问题是这样的:
当启动的主要活动列表视图是可见的(显然不够)。有没有一种方法,使无形的列表视图,只有在搜索栏,使列表视图的结果变得可见键入后?类似的在应用程序搜索的东西;还是我只是想象了?
My question is this: When launching the main activity the listview is visible (obviously enough). Is there a way to make the listview invisible and only after typing in the searchbar to make the results of the listview become visible? Something like an in app search thing; or am I just imagining things?
我希望,我不是什么我上面写的太混乱了。
I hope that I am not too confusing with what I wrote above.
我期待着您的答复,我感谢你在前进。
I am looking forward to your replies and I thank you in advance.
推荐答案
转到这种方式:
设置你的列表视图的可视性,从XML文件不见了或无形的:
Go this way: set your listview visibility to gone or invisible from your xml file:
android:visibility="gone"
现在申请textwatcher在搜索栏的EditText
Now apply textwatcher on searchbar edittext
edittext.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
//put your search logic here and populate listview.
//after populating listview set its visibility to visible
listView.setVisibility(View.VISIBLE);
//and set listview visibility to GONE again when user erase all text from search edittext
if(s.length() == 0){
listView.setVisibility(View.GONE);
} else {
listView.setVisibility(View.VISIBLE);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
这篇关于Android的搜索列表默认情况下不可见的?能不能做到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!