I have an issue in my application, i have a list view generated from database, i want when
the user click on an item that he will be deleted, i tried many solution but it's not
working, i did as a solution
arg0.removeView(arg0.getChildAt(position));
adapter.notifyDataSetChanged();
help please .
private void populateListViewFromDB() {
Cursor cursor = db.getAllRecords();
startManagingCursor(cursor);
String[] databaseColumnNames = new String[] { DBAdapter.col_Region };
int[] toViewIDs = new int[] { android.R.id.text1, android.R.id.text2 };
SimpleCursorAdapter myCursordapter = new SimpleCursorAdapter(this,
android.R.layout.simple_expandable_list_item_1, cursor,
databaseColumnNames, toViewIDs, FLAG_REGISTER_CONTENT_OBSERVER);
final ListView list = (ListView) findViewById(android.R.id.list);
list.setAdapter(myCursordapter);
final String items[] = { "Completer le questionnaire" };
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(final AdapterView<?> arg0, View arg1,
final int position, long arg3) {
Toast.makeText(getApplicationContext(), " " + position,
Toast.LENGTH_LONG).show();
AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
final String s = ((TextView)arg1).getText().toString();
builder.setTitle(s);
builder.setItems(items, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
db.insertest(s);
arg0.removeView(arg0.getChildAt(position));
adapter.notifyDataSetChanged();
Intent intent = new Intent(MainActivity.this, ActivityUn.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
}
});
AlertDialog alert = builder.create();
alert.show();