Filtered list item opens the original list items' activity

后端 未结 4 939
不知归路
不知归路 2021-01-28 09:23

After a tremendous amount of time searching in here, and everywhere else I am hopeless to find a solution.

So here is my problem.

I have created a list-

4条回答
  •  执笔经年
    2021-01-28 10:05

    The problem is that Adapter is populated once but with search results it gets overViewed by the searched items so on clicking it refers to the original items of list instead of the filtered list once , so we have to use the filtered lists' positions instead of the original one, i also faced this problem, try this:

    In your listView.setOnItemClickListener

    playersListView.setOnItemClickListener(new OnItemClickListener() {
     public void onItemClick(AdapterView parent, View view,int position, long id) {
    
        //Object objFilteredItem = parent.getItemAtPosition(position);
        //String a = searchResults.get(position);
    
        switch (Integer.parseInt((String) adapter.getItem(position))) {
        case 0:..
         Intent newActivity = new Intent(TeamsList.this,Barca.class);
         startActivity(newActivity);
         break;
    
        case 1:
         etc...
         break;
       }
     } 
    });
    

提交回复
热议问题