Android programming - onitemclicklistener for multiple listviews doesn't work

前端 未结 3 1798
礼貌的吻别
礼貌的吻别 2021-01-26 00:38

In my activity i have created seven listviews and am using viewpager to swipe between them in the same activity. I then have a sqlite database populating each listview. My probl

3条回答
  •  难免孤独
    2021-01-26 01:29

    From your describe I understand that the lists are showed up when you start the application.

    The position parameter, holds where the user clicked on the (screen) - list.

    Did you try to use it with switch case?

    I mean like this:

    list.setOnItemClickListener(new OnItemClickListener(){
                      public void onItemClick( AdapterView  parent, View view, int   
                                               position,long id){
    
                           switch(position){
                                case 0:
                               // write what you need here when the user clicks on the first list item
                                  break;
                                case 1:
                               // write what you need here when the user clicks on the 2nd list item 
                                   break;
                           }
                      }
                   };
    

    hope this will help you

提交回复
热议问题