ListView with longClick for showing and hiding Checkbox?

守給你的承諾、 提交于 2019-12-04 07:37:17

One possible solution is to hide/show the checkbox based on a flag that is toggled when an item receives a long click. Do something like this in your adapter's getView method:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ...
    if(showCheckBoxes) {
        v.findViewById(R.id.checkbox).setVisible(View.VISIBLE);
    } else {
        v.findViewById(R.id.checkbox).setVisible(View.GONE);
    }
    ...
}

and then in your long click listener:

dList.setOnItemLongClickListener(new OnItemLongClickListener() {
    public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) {
        showCheckBoxes = !showCheckBoxes;
        fileArrayAdapter.notifyDataSetChanged();
        return true;
    }
});

Its simple add checkbox in xml and make visibility gone

android:visibility="gone"

And declare a radiobox in FileArrayAdapter class as you did with textbox and the put your

onItemLongClickListener();

In that check if checkbox is visible then make it disappear or if not visible the make it visible.

if(cb.isVisible()){
    cb.setVisibility(View.GONE);
}else{
    cb.setVisibility(View.VISIBLE);
}

Thats's it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!