0

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?

  • Please explain, completely and precisely, what "does not work" means. Please also show where you are assigning a value to `position`. – CommonsWare Nov 11 '13 at 16:28
  • Check out this question and answer as it this sort of thing has been asked (a bit differently) before : http://stackoverflow.com/q/8910411/794088 – petey Nov 11 '13 at 16:33
  • Hello, sorry for the lack of information. By "does not work" I mean that the application remains in the list even if it was uninstalled. The position variable is declarated out of methods – user2976665 Nov 11 '13 at 16:35
  • @user2976665: How did you solved your problem? Actually I am doing same thing but onActivityResult() never called. Due to this ListView is not updating. – Sam Jan 18 '14 at 11:44

1 Answers1

0

did you check if the code gets into the :

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

part? and if so, did you try removing the positioned item from the adapter also?

Matan Dahan
  • 390
  • 5
  • 10