我有一个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();
}
}
你能帮我解决一下吗?
答案 0 :(得分:0)
你检查代码是否进入:
if (resultCode == RESULT_OK && requestCode == 1)
部分? 如果是这样,你是否尝试从适配器中删除定位的项目?