android listview check 隐藏,Android listview with check box

In my case i have two text view and one check box in listview. I am using ArrayAdapter class to set the data in textviews.

When i select any check box and scroll in list view some check boxes are automatically selected.I am not getting why is this happening below is my code please look the code and give the solution to solve this out.

public class Contacts_NumberActivity extends Activity {

/** Called when the activity is first created. */

String nameList[] = { "U", "A", "B", "C", "D", "E", "F", "G", "H",

"I", "J", "L", "M", "N", "O", "P", "Q" }, numberList[] = { "1",

"2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3", "4",

"5", "6", "7" };

ListView contactList;

boolean[] checked;

ContactHolder holder = null;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

contactList = (ListView) findViewById(R.id.contact_list);

contactList.setAdapter(new ContactAdapter(this, R.layout.list_item,

nameList, numberList));

}

public class ContactAdapter extends ArrayAdapter {

Context context;

int layoutResourceId;

String data[] = null;

String data1[] = null;

public ContactAdapter(Context context, int layoutResourceId,

String[] data, String[] data1) {

super(context, layoutResourceId, data);

this.layoutResourceId = layoutResourceId;

this.context = context;

this.data = data;

this.data1 = data1;

}

@Override

public View getView(final int position, View convertView,

ViewGroup parent) {

View row = convertView;

if (row == null) {

LayoutInflater inflater = ((Activity) context)

.getLayoutInflater();

row = inflater.inflate(layoutResourceId, parent, false);

holder = new ContactHolder();

holder.name = (TextView) row.findViewById(R.id.name);

holder.number = (TextView) row.findViewById(R.id.number);

holder.chkbox = (CheckBox) row.findViewById(R.id.checkBox1);

holder.chkbox

.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override

public void onCheckedChanged(

CompoundButton buttonView, boolean isChecked) {

holder.chkbox.setChecked(isChecked);

System.out.println("Checked possition= "

+ isChecked);

}

});

row.setTag(holder);

} else {

holder = (ContactHolder) row.getTag();

}

holder.name.setText(data[position]);

holder.number.setText(data1[position]);

return row;

}

public class ContactHolder {

TextView name, number;

CheckBox chkbox;

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值