长按不能卸载应用程序

时间:2013-10-27 12:19:04

标签: java android listview android-listview onlongclicklistener

我在listview中出现错误,只需单击鼠标即可卸载此列表视图中的应用程序显示。代码是这样的:

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。感谢

2 个答案:

答案 0 :(得分: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;
            }
        });

答案 1 :(得分:0)

  

我已经实现了OnLongClickListener

将其更改为OnItemLongClickListener

同时将protected boolean setOnItemLongClickListener更改为@Override protected boolean onItemLongClick