0

我有一个安装了所有应用程序的列表视图。我需要onItemLongClick卸载我在列表视图中单击的应用程序。onItemLongClick 的起始代码是这个:

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

这是用于卸载:

ApplicationInfo app = applist.get(position);

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

        return true;

我还需要插入一些参数,我尝试了这个,但我有一个错误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;
    }

我该如何解决?

4

1 回答 1

1

尝试实现这一点

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;
            }
        });
于 2013-10-28T10:41:38.347 回答