jeudi 21 janvier 2016

use Custome ListView with TextView And CheckBox With Single Selection of CheckBox

Hear i use Custom ListView with TextView and CheckBox. But i want that Single Selection in CheckBox At a time One CheckBox Selected then other one is Deselect using BaseAdapter but This code not Work Properly .. Please Give me Suggestion ..thnks

@Override
public View getView(final int position, View view, ViewGroup parent) {
    Integer selected_position = -1;
    holder = new ViewHolder();
    final Items itm = rowItem.get(position);
    LayoutInflater layoutInflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (view == null) {

        view = layoutInflater.inflate(R.layout.activity_custom_list,
                parent, false);

        holder.tvItemName = (TextView) view.findViewById(R.id.textView1);
        holder.check = (CheckBox) view.findViewById(R.id.checkBox1);
        view.setTag(holder);

    } else {
        holder = (ViewHolder) view.getTag();
    }

    holder.tvItemName.setText(itm.getItems());

    if (position == selected_position)
        holder.check.setChecked(true);
    else
        holder.check.setChecked(false);

    holder.check.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (holder.check.isChecked()) {
                selected_position = position;
            } else {
                selected_position = -1;
            }
            notifyDataSetChanged();

        }
    });

    return view;
}}




Aucun commentaire:

Enregistrer un commentaire