Cursor smCursor = getContentResolver().query(
Uri.parse("content://contact"),
new String[] { "_id", "address", "body" }, "address like?",
new String[] { searchContactPhone }, null);
CustomAdapter ada = new CustomAdapter(this,
R.layout.sm_layout, smCursor, new String[] {
"body" }, new int[] {
R.id.txt2 });
lvSm.setAdapter(ada);
btnDel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ArrayList<Boolean> ca = ada.getItemsThatAreChecked();
// this ArrayList will hold our Strings from the rows that were clicked.
ArrayList<String> results = new ArrayList<String>();
int s = ca.size();
for (int i = 0; i < s; i++) {
if (ca.get(i).booleanValue()) {
smCursor.moveToPosition(i);
Log.v("sss", smCursor.getString(smCursor.getColumnIndex("_id")));
results.add(smCursor.getString(smCursor.getColumnIndex("_id")));
}
}
if(results != null && !results.isEmpty()){
String [] mSelectionArgs = results.toArray(new String[results.size()]);
String mSelectionClause = "_id=?";
int delCursor = 0;
Uri uri = Uri.parse("content://contact");
for(int delCount = 0;delCount < mSelectionArgs.length;delCount++)
{
delCursor = getContentResolver().delete(uri ,mSelectionClause,new String[]{mSelectionArgs[delCount]});
}
ada.notifyDataSetChanged();
Toast.makeText(getApplicationContext(), mSelectionArgs.length +" number of rows deleted", 5).show();
}
else
Toast.makeText(getApplicationContext(), "Sorry no deletion occurs", 5).show();
}
我想知道如何更新我的列表视图,因为我正在从列表视图中删除选定的项目,删除后选择会自动发生到下一个项目。我使用了 notifyDataSetChanged() 但不起作用。我正在使用自定义适配器。