【发布时间】:2014-01-01 06:07:48
【问题描述】:
我在片段中有一个可扩展的列表视图,其中包含该部分,并且在该部分下我有不同的产品。我在操作栏中有 searchview,我从那里搜索产品。
现在我所做的是在加载 listview 时,我折叠了所有组,现在当用户开始搜索产品时,我想过滤相应的组,我已经完成了,但结果是组没有得到扩展,(希望我不会让事情变得很混乱......)
现在我在 searchview 中搜索产品名称“sony”,我得到了过滤结果,但组没有扩展,我想扩展组并显示相关组下的产品名称。
我创建了这两种方法:
private void expandAll()
{
int count = listAdapter.getGroupCount();
for (int i = 0; i < count; i++)
{
expListView.expandGroup(i);
}
}
private void collapseAll()
{
int count = listAdapter.getGroupCount();
for (int i = 0; i < count; i++)
{
expListView.collapseGroup(i);
}
}
当我的片段在可扩展列表视图中加载数据时,我调用了 collapseAll() 方法。
所以现在如果我在搜索产品时调用 expandAll() 方法并没有得到预期的结果。
这就是我过滤列表的方式:
public void filterData(String query)
{
//query = query.toLowerCase();
//query=query;
ArrayList<ProSectionName> filterProSectionNames=prepareFilterListData(query);
if(query.isEmpty())
{
if(txtNoProductMessage.getVisibility()==View.VISIBLE)
{
txtNoProductMessage.setVisibility(View.GONE);
}
listDataHeader.addAll(mNewTopupGroupCollection);
}
if(filterProSectionNames!=null && filterProSectionNames.size()>0)
{
if(txtNoProductMessage.getVisibility()==View.VISIBLE)
{
txtNoProductMessage.setVisibility(View.GONE);
}
listDataHeader.clear();
for(ProSectionName proSectionName : mNewSectionGroupCollection)
{
ArrayList<ProSectionName.Products> productList = proSectionName.getProductList();
ArrayList<ProSectionName.Products> newProductList = new ArrayList<ProSectionName.Products>();
for(ProSectionName.Products products : productList)
{
if(products.getProductName().toLowerCase().contains(query.toLowerCase()) ||products.getProductName().toLowerCase().contains(query.toLowerCase()))
{
newProductList.add(products);
}
}
if(newProductList.size() > 0)
{
ProSectionName proSectionName = new ProSectionName(ProSectionName.getsectionName(),newProductList);
listDataHeader.add(topupSectionName);
//expandAll();
}
else
{
txtNoProductMessage.setVisibility(View.VISIBLE);
txtNoProductMessage.setText("No Match Found...");
}
}
//Log.v("MyListAdapter", String.valueOf(topupProducts.size()));
}
else
{
txtNoProductMessage.setVisibility(View.VISIBLE);
txtNoProductMessage.setText("No Match Found...");
}
notifyDataSetChanged();
}
我面临的问题是当我在filterdata() 中调用expandAll() 时,我的列表组得到了正确扩展,但我的软键盘不见了。我也想将键盘保留在那里,直到用户按下回。
【问题讨论】:
-
既然您可以确定哪个组包含您要搜索的项目,为什么不使用位置扩展组??
-
@TheUnknown 你能解释一下吗?任何 sn-p 示例(伪)代码都会有所帮助...
-
您已经知道要正确显示哪个父组(如果这就是您所说的“我想过滤相应的组,我已经这样做了,但结果是该组没有得到扩展"),在这种情况下,u cud 循环遍历可能 b 并获取每个父组的位置,而不是调用 collapse,调用 expand。
-
如果 notifydata set changed 不起作用,请尝试再次设置适配器,cz 有时确实不起作用。
-
我认为,您应该关注
SearchView是如何失去焦点的。也许,您添加了一些听众,他们使键盘隐藏。你能在你操作SearchView的地方添加代码吗?
标签: android listview android-listview android-fragments expandablelistview