问题是所选数据出现在列表视图中,但实际上我们想从列表视图中删除数据,检查是否意味着删除位置
任何人都可以加入我们解决问题
编码
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(data!=null){enter code here
Bundle bundle = data.getExtras();
if(requestCode ==1){
selectedConatcts = bundle.getStringArrayList("sel_contacts");
Log.v("", "Selected contacts-->"+selectedConatcts);
if(selectedConatcts.size()<0){
}else{
for(int i =0;i<selectedConatcts.size();i++){
RelativeLayout lnr_inflate = (RelativeLayout)View.inflate(thisActivity, R.layout.contacts_inflate, null);
// EditText edt = (EditText)lnr_inflate.findViewById(R.id.edt_contact);
String selectednames =selectedConatcts.get(i) ;
List<String> stringList = new ArrayList<String>(Arrays.asList(selectednames));
final ListView edt = (ListView)lnr_inflate.findViewById(R.id.edt_contact);
ArrayAdapter<String> adaptercon = new ArrayAdapter<String>(thisActivity, android.R.layout.select_dialog_multichoice,stringList);
edt.setAdapter(adaptercon);
edt.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
edt.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0,
View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
final int len = edt.getCount();
final SparseBooleanArray checked = edt.getCheckedItemPositions();
for(int i =0;i<len;i++){
if (checked.get(i)) {
// selectedContacts.add(names[i]);
// selectedConatcts.get(i);
// selectedConatcts.remove(i);
selectedConatcts.remove(phone_nos[i]);
contactdisp.removeViewAt(i);
//you can you this array list to next activity
// do whatever you want with the checked item
}
// selectedConatcts.get(i);
System.out.println("i m in check button cheked"+selectedConatcts.get(i));
}
selectedConatcts.remove(phone_nos[arg2]);
contactdisp.removeViewAt(arg2);
}
});
contactdisp.addView(lnr_inflate);
}}}}
答案 0 :(得分:0)
更好地检查复选框是否已选中或是否在button_click下编写代码
删除项目
remove selectedConatcts.remove(phone_nos[arg2]); contactdisp.removeViewAt(arg2);