how to add custom listview number of click to action bar in android

后端 未结 2 1961
无人共我
无人共我 2021-01-27 12:55

Please help me how to add custom List view\'s number of clicks to custom action bar (textview) in android?

Here is my Activity Class

public         


        
2条回答
  •  清酒与你
    2021-01-27 13:38

    Ok so first of all declare a instance variable to keep the count of the clicks.

    public int listViewClickCounter;
    

    The on your listview onclick increment the count and call the change action bar method

        yourListView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView parent, View view, int position,
                    long id) {
    
                listViewClickCounter++ 
                changeActionBarTitle();
            }
        });
    

    Then implement the change action bar method. You said you have a custom view so you may need to change this a little

    public void changeActionBarTitle() {
    
    myActionBarCustomTitle.setText("number of clicks =" + String.valueOf(listViewClickCounter));
    

提交回复
热议问题