Handling button event in each row of Listview issue

后端 未结 2 1745
滥情空心
滥情空心 2021-01-23 02:43

I am new to android and am trying to develop a new android app. But I am struggling to siolve one of the problems in my project.

I am using a listview extended from

2条回答
  •  终归单人心
    2021-01-23 03:06

    You have an adapter, activity and some sort of data source

    In your adapter you attach some data to buttons to be able to tell one from another:

    public class ExpAdapter extends ListAdapter {
    
        @Override
        public View getView(int groupPosition, boolean isExpanded,
                View convertView, ViewGroup parent) {
                    /* SOME CODE HERE*/
            convertViewButton.setTag(buttonId);
            return convertView;
        }
                    /* SOME CODE HERE*/
    }
    

    in your activity you mark button id as the one to be hidden:

            public boolean onItemLongClick(AdapterView arg0, View arg1,
                    int arg2, long arg3) {
                storageOfHiddenButtonsIds.add((Long)arg1.getTag());
            }};
    

    and then ListAdapter changes like this:

    @Override
    public View getView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
                /* SOME CODE HERE*/
    
        convertViewButton.setTag(buttonId);
    
        if(storageOfHiddenButtonsIds.contains(buttonId))
        {
          convertViewButton.setVisiblity(View.GONE);
        }
        return convertView;
    }
    

    and when you want your adatper to change you, don't forget to call

    this.expAdapterAllTaks.notifyDataSetChanged();
    

    Sorry for any errors in my code, but i just wanted to give you an idea.

提交回复
热议问题