0

我有一个 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();            
                }

    }

你能帮我解决吗?

4

1 回答 1

0

你检查过代码是否进入:

if (resultCode == RESULT_OK && requestCode == 1) 

部分?如果是这样,您是否也尝试从适配器中删除定位的项目?

于 2013-11-11T16:33:50.800 回答