我有一个 ListView,当我单击一个项目时,它会卸载选定的应用程序。问题是,一旦您卸载它,它就会保留在 ListView 中。我的目标是在卸载后将其从列表中删除。我已经完成了这段代码,但不起作用。
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();
}
}
你能帮我解决吗?