您可以做的是,在您的自定义 SearchViewAdapter(即)您设置的类(上下文、资源、Arraylist)中,您可以创建一个方法来存储传递给 SearchViewAdapter 的原始 ArrayList 并创建一个获取原始位置的方法从 listView 中选择的对象:
//in your custom SearchViewAdapter create methods store() and getPos()
public void store(ArrayList<SearchViewClass>originalList){
mylist=new ArrayList<>(originalList);
} //The store method should be called once in searchView Activity when you pass all needed values into your Arraylist
public int getPos(Object obj){
return mylist.indexOf(obj);
}
然后在您的 SearchView Activity 或您正在实现 searchView 的任何地方,在 listView.setOnItemClickListener 上,您调用 getpos(adapterView.getItemAtPosition(i)) 方法,该方法将 adapterView.getItemAtPosition(i) 作为参数。getpos()方法返回原始对象位置的索引,不管searchView引起的过滤。然后可以在索引上switch(),
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
switch (searchViewAdapter.getPos(adapterView.getItemAtPosition(i))){
case 0:...break}
}