我有一个片段中的可扩展列表视图,其中包含一个部分,在这个部分下我有不同的产品。我在操作栏中有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(); }我面临的问题是当我在我的列表组中调用expandAll()时,我的列表组得到了正确的扩展,但我的软键盘不见了。我想把键盘也放在那里,直到用户按回来。 最佳答案 它将如未知者所说的那样工作,如下所述通过搜索,找出目标的组位置/数量,假设目标属于数据适配器中的n组。调用调用这就不需要调用任何额外的方法了。软键将保持在屏幕上。
10-05 21:41