我希望获得带有复选框的列表视图的位置文本.Listview包含来自baseadapter的textview和复选框
holder = new ViewHolder();
holder.full_name = (TextView) convertView
.findViewById(R.id.social_name);
holder.social_network_pic = (ImageView)convertView.findViewById(R.id.social_image);
holder.checkBox = (CheckBox)convertView.findViewById(R.id.social_check_box);
convertView.setTag(holder);
Log.e("Position=", "" + position);
holder = (ViewHolder) convertView.getTag();
String holderValue = socila_network_name_arraya_list.get(position).get("serviceLabel").toString();
holder.full_name.setText(socila_network_name_arraya_list.get(position).get("serviceData").toString());
int resID = getResources().getIdentifier(holderValue , "drawable", getPackageName());
holder.social_network_pic.setImageResource(resID);
holder.checkBox.setOnClickListener(CreatePost.this);
holder.checkBox.isChecked();
之后我没有得到如何做到这一点我需要紧急:0
答案 0 :(得分:0)
试用此代码
以下代码使用适配器初始化ListView
list.setAdapter(new ArrayAdapter(Download_ReadyList.this,
android.R.layout.simple_list_item_multiple_choice, item));
for (int i = 0; i < result.length; i++) {
list.setItemChecked(i, true);
}
以下代码获取ListView以查看
int cntChoice = list.getCount();
String checked[] = new String[list.getCheckedItemCount()];
SparseBooleanArray sparseBooleanArray = list.getCheckedItemPositions();
ArrayList<HashMap<String, String>> list_offline = new ArrayList<HashMap<String, String>>();
int Count = 0;
for (int i = 0; i < cntChoice; i++) {
if (sparseBooleanArray.get(i) == false) {
checked[Count] = list.getItemAtPosition(i).toString();
Count++;
}
}