1
public void filter(String charText)
{       
    charText = charText.toLowerCase(Locale.getDefault());
    dataOrig.clear();

    if (charText.length() == 0)
    {           
        dataOrig.addAll(arraylist);
    }
    else
    {
    for (User wp : arraylist)
        {   
            if (wp.name.toLowerCase(Locale.getDefault()).contains(charText))
            {
                dataOrig.add(wp);
            }   
        }
    }

    //check if the list is correct... it is :/
    for (int i = 0; i < dataOrig.size(); i++)
    {
        Log.i(tag, dataOrig.get(i).name);
    }
    notifyDataSetChanged();
}

但是, notifyDataSetChanged(); 使错误的项目出现在列表视图中;即使 for 循环显示正确的项目被放入 dataOrig 中。

4

0 回答 0