我在擴張列表視圖搜索後有我的onClick問題。當我搜索我得到正確的結果,但是當我單獨點擊他們時敬酒的價值,我得到不同的結果?好心幫搜索列表視圖擴展與onGroupClick&onChildClick顯示錯誤的結果
我的方法來篩選我的數據搜索
public void filterData(String query){
query=query.toLowerCase();
parentRowArrayList.clear();
if(query.isEmpty()){
parentRowArrayList.addAll(originalList);
}else{
for(ParentRow parentRow:originalList){
ArrayList<ChildRow> childList = parentRow.getChildList();
ArrayList<ChildRow> newList = new ArrayList<>();
for(ChildRow childRow:childList){
if(childRow.getText().toLowerCase().contains(query)){
Toast.makeText(context, childRow.getText().toString(), Toast.LENGTH_SHORT).show();
newList.add(childRow);
}
}//end for ChildRow childRow:childList
if(newList.size()>0){
ParentRow newParentRow = new ParentRow(parentRow.getName(),newList);
parentRowArrayList.add(newParentRow);
}
} // end for ParentRow parentRow:originalList
} //end else
notifyDataSetChanged();
}
我OnChildClickListener
myList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
parentRowArrayList.get(groupPosition).getChildList()
.get(childPosition).getText() +"",
Toast.LENGTH_SHORT)
.show();
return false;
}
});
我OnGroupClickListener
myList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
Toast.makeText(getApplicationContext(),
"Group Clicked " + parentRowArrayList.get(groupPosition).getName(),
Toast.LENGTH_SHORT).show();
return false;
}
});
搜索查看實現的方法
@Override
public boolean onClose() {
listAdapter.filterData("");
expandAll();
return false;
}
@Override
public boolean onQueryTextChange(String query) {
listAdapter.filterData(query);
myList.setAdapter(listAdapter);
listAdapter.notifyDataSetChanged();
expandAll();
return false;
}
@Override
public boolean onQueryTextSubmit(String query) {
listAdapter.filterData(query);
myList.setAdapter(listAdapter);
listAdapter.notifyDataSetChanged();
expandAll();
return false;
}
是適配器的篩選數據方法的一部分? – Rohit
filterData在適配器類 –