0

I don't want to call onItemClick when onItemLongClick is called. I am using SlideAndDragListView and returning true only in onItemLongClick.

matchedUsersListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { 
            InviteMatchedUsersFragment.this.onItemLongClick(parent,view,position,id);
            return true;
        }
    });

 @Override
    public void onItemLongClick(AdapterView<?> parent, View view, int position, long id) {  
        ImageView view1 = (ImageView) view.findViewById(position);
        matchedPassengersAdapter.onUserClick(view1, position);
    } 

In OnItemClick I am doing it differently

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Log.d(LOG_TAG, "onMatchedUserSelection()");
    if(matchedPassengersAdapter.getSelectedPassengersCount() != 0)
    {
        ImageView view1 = (ImageView) view.findViewById(position);
        matchedPassengersAdapter.onUserClick(view1, position);
    }
    else {
          //onItemClickGoesHere
    }

}

@Override
    public void onItemLongClick(AdapterView<?> parent, View view, int position, long id) {  
        ImageView view1 = (ImageView) view.findViewById(position);
        matchedPassengersAdapter.onUserClick(view1, position);
    }  
Bunny
  • 1,044
  • 12
  • 23

1 Answers1

0

This May helps You

Ref: Set long click listener for listview

Your question is very similar to this one, but it looks like it's not an exact duplicate.

What you've noticed is that the ListActivity class does not have a method override specifically for this case.

In order to add this functionality as a method override, your class should implement the AdapterView.OnItemLongClickListener interface, and then you can add the onItemLongClick() method override, which acts just as the onListItemClick() method override you already have, but responds to long clicks.

Just make sure that you follow instructions from this answer, you must use android:longClickable="true" in the layout xml, or call listview.setLongClickable(true);

Ex

public class MainActivity extends ListActivity implements AdapterView.OnItemLongClickListener {

    ListView listview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView listview = (ListView) findViewById(R.id.list);

        listview.setLongClickable(true);

    }

    @Override
    public boolean onItemLongClick(AdapterView<?> l, View v,
                                   final int position, long id) {

        Toast.makeText(this, "long clicked pos: " + position, Toast.LENGTH_LONG).show();

        return true;
    }

    protected void onListItemClick(ListView l, View v, final int position, long id) {
        super.onListItemClick(l, v, position, id);

        Toast.makeText(this, "short clicked pos: " + position, Toast.LENGTH_LONG).show();  

    }

 //....................
Ashvin solanki
  • 4,802
  • 3
  • 25
  • 65