私の展開可能なリストビューで検索した後にonClickに問題があります。私は正しい結果を得ることができますが、個別にクリックしたときに値をトーストすると、別の結果が得られますか?親切に検索onGroupClickとonChildを使用してExpandable Listviewを検索すると、間違った結果が表示されます
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;
}
});
SearchView実装されたメソッドを助ける
@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;
}
filterDataメソッドはアダプタの一部ですか? – Rohit
filterDataはアダプタクラス –