0

I have used this code to get check boxes in app list,it works fine but when we clicked on the box it forcefully closes the app the code is here

@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;
}
Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68

1 Answers1

0

move the initialization inside and check

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);
} 
Sunil P
  • 3,698
  • 3
  • 13
  • 20