Android 从searchview搜索时,在可展开的listview中展开组

Android 从searchview搜索时,在可展开的listview中展开组,android,listview,android-listview,android-fragments,expandablelistview,Android,Listview,Android Listview,Android Fragments,Expandablelistview,我在片段中有一个可扩展的listview,其中包含该部分,在该部分下我有不同的产品。我在操作栏中有searchview,我在这里搜索产品 现在我所做的是在加载listview时,我折叠所有组,现在当用户开始搜索产品时,我想过滤相应的组,我已经这样做了,但结果是组没有得到扩展,(希望我没有让事情变得非常混乱…) 现在,我在searchview中搜索产品名称“sony”,我得到了过滤结果,但组没有扩展,我想扩展组并显示相关组下的产品名称 我创建了这两种方法: private void expand

我在片段中有一个可扩展的listview,其中包含该部分,在该部分下我有不同的产品。我在操作栏中有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);
        }
    }
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();
    }
private void expandAll()
{
int count=listAdapter.getGroupCount();
for(int i=0;i
当片段在可展开的listview中加载数据时,我调用了collapseAll()方法

现在如果我在搜索产品时调用expandAll()方法,但没有得到预期的结果

我就是这样筛选列表的:

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);
        }
    }
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();
    }
public void filterData(字符串查询)
{
//query=query.toLowerCase();
//查询=查询;
ArrayList filterProSectionNames=prepareFilterListData(查询);
if(query.isEmpty())
{
if(txtNoProductMessage.getVisibility()==View.VISIBLE)
{
txtNoProductMessage.setVisibility(View.GONE);
}
addAll(mnewtoupgroupcollection);
}
if(filterprosecoctionnames!=null&&filterprosecoctionnames.size()>0)
{
if(txtNoProductMessage.getVisibility()==View.VISIBLE)
{
txtNoProductMessage.setVisibility(View.GONE);
}
listDataHeader.clear();
for(ProSectionName ProSectionName:mNewSectionGroupCollection)
{
ArrayList productList=proSectionName.getProductList();
ArrayList newProductList=新ArrayList();
对于(ProSectionName.Products:productList)
{
如果(products.getProductName().toLowerCase().contains(query.toLowerCase())| | products.getProductName().toLowerCase().contains(query.toLowerCase())
{
新增产品列表。添加(产品);
}
}
如果(newProductList.size()>0)
{
ProSectionName ProSectionName=新ProSectionName(ProSectionName.getsectionName(),newProductList);
添加(topupSectionName);
//expandAll();
}
其他的
{
txtNoProductMessage.setVisibility(View.VISIBLE);
txtNoProductMessage.setText(“未找到匹配项…”);
}
}
//Log.v(“mylistapter”,String.valueOf(toupproducts.size());
}
其他的
{
txtNoProductMessage.setVisibility(View.VISIBLE);
txtNoProductMessage.setText(“未找到匹配项…”);
}
notifyDataSetChanged();
}

我面临的问题是,当我在我的
filterdata()
列表组中调用
expandAll()
时,列表组得到了正确的扩展,但我的软键盘不见了。我想在用户按下back键之前将键盘保持在那里。

它将按照未知的指示工作,如下所示

  • 从搜索中,找出目标的组位置/编号,例如目标属于数据适配器中的
    n

  • 调用expListView.smoothScrollToPosition(n)

  • 调用expListView.expandGroup(n)


  • 这一切都不需要调用任何额外的方法。软键将保持原样在屏幕上。

    既然您可以分辨出哪个组包含您正在搜索的项目,为什么不使用位置扩展组??@TheUnknown您能再解释一下吗?任何代码片段示例(psuedo)代码都会很有帮助……您已经知道要正确显示哪个父组(如果这就是您所说的“我想筛选相应的组,我已经完成了,但结果是该组没有得到扩展”),在这种情况下,u cud循环通过may b并获取每个父组的位置,而不是调用collapse,而是调用expand。如果notifydata set changed不起作用,请尝试再次设置适配器,cz有时确实不起作用。我认为,您应该关注
    SearchView
    是如何失去焦点的。也许,您在其中添加了一些侦听器,它们会隐藏键盘。您能在操作
    SearchView
    的地方添加代码吗?