Skip to content Skip to sidebar Skip to footer

I Cannot Set OnLongClick Listener

Newest Edit ---------------------------------------------------------------------------- I updated code and it is correct now, although I cannot get the functionality to run. On lo

Solution 1:

Listview can not have setonLongClickListener you are supposed to implement the setOnItemItemLongClickListener as ListView contains the list of items so you can always implement the its items long click listener as below:

listView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view,
                int position, long id) {
            // TODO Auto-generated method stub
            return false;
        }
    });

Solution 2:

ListView listView = new ListView(this);

You should pass to ListView constructor a context, not a MyDiary object.

Fix it using

ListView listView = new ListView(Monday.this);

It should work since your MyDiary is an innerclass of Monday and is not static.

If you change this, you should pass to MyDiary constructor the Context of the activity and use it.


And, for your next question: You should use OnItemLongClickListener in a ListView, not OnLongClickListener.


Post a Comment for "I Cannot Set OnLongClick Listener"