Question

How to make AdapterView.OnItemClickListener() work, when

... activity implements View.OnLongClickListener, View.OnClickListener,
DragDropPresenter,
View.OnTouchListener { ... }

and I there is

public void onClick(View v) {
    // TODO Auto-generated method stub

}

to handle clicks? Idea is that drag and drop is activated on a long click, and the OnItemClickListener method is used on a short click. Is it even possible?

Was it helpful?

Solution 2

I overcame the problem of handling short clicks by assigning each cell a tag and then reading the tag with the simple onClick listener:

public void onClick(View v) {
    Integer position = (Integer)v.getTag();
    if (position = ...){ do some stuff }
}

OTHER TIPS

Your question is a bit simplified but I hope that the example below will be helpful:

public class MainActivity extends Activity implements OnClickListener, OnItemClickListener, OnItemLongClickListener  {

....
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    .....
    listView.setAdapter(adapter); 
    listView.setOnItemLongClickListener(this);
    listView.setOnItemClickListener(this);
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    .....

}

@Override
public boolean onItemLongClick (AdapterView<?> parent, View item, int position, long id) {
....
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top