Question

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

Was it helpful?

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;
            }
        });

OTHER TIPS

i've already implements the OnLongClickListener

Change that to be OnItemLongClickListener.

Also change protected boolean setOnItemLongClickListener to be @Override protected boolean onItemLongClick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top