Android编程:ListView CheckBox变得可见

时间:2017-04-07 12:50:08

标签: android listview checkbox visible invisible

我正在创建一个带有复选框的ListView,该复选框最初是Visibility:Gone。我想长按一个项目时查看所有复选框,但有些项目没有显示复选框,当我滚动时它会改变。我想使它与messagin应用程序一样,我可以通过选择多个复选框删除多个项目。

lists[0].setLongClickable(true);
    lists[0].setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            CheckBox selectAll = (CheckBox) findViewById(R.id.selectAll);
            selectAll.setVisibility(View.VISIBLE);

            int count = lists[0].getChildCount();
            int adapter = myAdapter[0].getCount();
            Toast.makeText(getBaseContext(), Integer.toString(adapter), Toast.LENGTH_LONG).show();
            for (int i = 0; i < adapter; i++) {
                View v = (View) lists[0].getItemAtPosition(i);
                CheckBox box = (CheckBox) v.findViewById(R.id.checkBoxSelect);
                box.setVisibility(View.VISIBLE);
            }
            return true;
        }
    });

    myAdapter[0].notifyDataSetChanged();
    lists[0].setAdapter(myAdapter[0]);

This is the output of my Code

0 个答案:

没有答案