문제

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

도움이 되었습니까?

해결책

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

다른 팁

i've already implements the OnLongClickListener

Change that to be OnItemLongClickListener.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top