0

使用长按卸载此列表视图中显示的应用程序时,我的列表视图中出现错误。代码是这样的:

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 method onItemLongClick(ListView, View, int, long) is undefined for the type ListActivity如何解决?我已经实现了OnLongClickListener. 谢谢

4

2 回答 2

1

尝试直接从您的 listView 调用侦听器

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:59:29.463 回答
0

我已经实现了 OnLongClickListener

将其更改为OnItemLongClickListener.

protected boolean setOnItemLongClickListener改成@Override protected boolean onItemLongClick

于 2013-10-27T12:21:54.450 回答