Search code examples
javaandroidlistviewandroid-listviewonlongclicklistener

Can't uninstall application with long click


I get an error in my listview using long click to uninstall an application display in this listview. The code is this:

protected boolean setOnItemLongClickListener(ListView l, View v, int position, long id) {
        super.onItemLongClick(l, v, position, id);// Error

        ApplicationInfo app = applist.get(position);

        Uri packageUri = Uri.parse("package:"+app.packageName);
        Intent uninstallIntent =
          new Intent(Intent.ACTION_DELETE, packageUri);
        startActivity(uninstallIntent);

        return true;
    }

the error is : The method onItemLongClick(ListView, View, int, long) is undefined for the type ListActivity How can i solve? i've already implements the OnLongClickListener. Thanks


Solution

  • Try to call the listener from your listView directly

    yourListView.setOnItemLongClickListener(new OnItemLongClickListener() {
    
                @Override
                public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {
                    // TODO Auto-generated method stub
                    Toast.makeText(MainActivity.this, "delete item in position : " + arg2, Toast.LENGTH_SHORT).show();
                    return false;
                }
            });