Listview item clicks

后端 未结 1 624
孤独总比滥情好
孤独总比滥情好 2021-01-07 07:24

I have a listview with some items.I want to know the list item click.for example if i click on listview item 1st time a toast message will be a appeared.again same item clic

相关标签:
1条回答
  • 2021-01-07 08:11

    You can add an additional ArrayList, that will contain a counter for each of your list view items.

    Let say that you have:

    ArrayList<String> listViewData = getSomeData();
    ArrayList<Integer> dataClickCount = new ArrayList<>();
    for(String item : listViewData)
    {
        dataClickCount.add(0);
    }
    

    And later in your listener:

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    
       if(dataClickCount.get(posion)%2==0){
           Toast.makeText(getApplicationContext(), "Clicked on Row1nd, odd click: " + country.getName(), Toast.LENGTH_LONG).show();
           dataClickCount.set(posion,1);
       }
       else{
           Toast.makeText(getApplicationContext(), "Clicked on Row2st, even click: " + country.getName(), Toast.LENGTH_LONG).show();
            dataClickCount.set(posion,0);
       }
    
    
    }});
    
    0 讨论(0)
提交回复
热议问题