检查完复选框后,我的应用程序关闭了力量

时间:2017-09-20 13:56:42

标签: android checkbox

我已经使用此代码获取应用列表中的复选框,它工作正常但是当我们点击框时它强行关闭应用代码在这里

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;

    if (view == null) {
        LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = vi.inflate(R.layout.custom_row_layout, null);
    }


    ImageView icon = (ImageView) view.findViewById(R.id.icon);
    TextView text = (TextView) view.findViewById(R.id.text);

    CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkBox);

    final AppDetails item = data.get(position);

    text.setText(item.name);
    icon.setImageDrawable(item.icon);

    checkBox .setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // Handle your conditions here

            }
        });


    return view;
}

1 个答案:

答案 0 :(得分:0)

在里面移动初始化并检查

if(view == null){

    ImageView icon = (ImageView) view.findViewById(R.id.icon);
    TextView text = (TextView) view.findViewById(R.id.text);

    CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkBox);
}