ListView.getCheckedItemPositions not able to return checked Items in SparseBooleanArray

大城市里の小女人 提交于 2019-12-05 10:04:24
Siten

I think you should use List Adapter view.

It will give an onCheckedChanged listener, so you will also get the position.

Like...

holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                int cupos = position+1;

            }
        });         

Now look the whole example:

Listview.setAdapter(new settingsBase(getApplicationContext()));

private class settingsBase extends BaseAdapter{

    public settingsBase(Context context) {
       layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return listview.length;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder ;
     holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                int cupos = position+1;

            }
        });         


        return convertView;
    }

    class ViewHolder{
        TextView txtSettingname , txtShow ;
        RadioButton radioButton ;
    }       
}

Try this--it will help you to get the position and whether checked true or false.

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