简体   繁体   中英

Listview and onItemLongClick doesn't work

i've got a listview with all applications installed.. I need that onItemLongClick uninstall the application i click in the listview. The starting code for the onItemLongClick is this one:

@Override
    public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
        // TODO Auto-generated method stub
        return false;
    }

And this is for uninstall:

ApplicationInfo app = applist.get(position);

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

        return true;

i need also insert some parameters and i tryied this one but i have an error in onItemLongClick :

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

how can i solve?

try to implement this

import android.widget.AdapterView.OnItemLongClickListener;


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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM