I have a ListView and when i click on an item, it uninstall the selected application. The problem is that once you uninstalled it remains in the ListView. My aim is to remove it from the list once it has been uninstalled. I have done this code but does not work.
int position;
ApplicationAdapter adapter;
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
int requestCode = 1;
AppInfo app = appInfoArrayList.get(position);
Uri packageUri = Uri.parse("package:"+app.packagename);
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageUri);
startActivityForResult(uninstallIntent, requestCode);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == 1)
{
appInfoArrayList.remove(position);
adapter.notifyDataSetChanged();
}
}
Can you help me to fix?