问题
Both the methods are being called when I do a long click on Google TV, but only the appropriate one is called with the same code on a tablet. Any ideas how to handle onItemLongClick without triggering onListItemClick on GoogleTV?
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Log.i(DEBUG_TAG, "onListItemClick");
WeatherData.getSingleton(getActivity().getApplication()).setCurrentLocationCode(WeatherData.getSingleton(getActivity().getApplication()).getLocCodes().get(position));
getListView().setItemChecked(position, true);
}
public boolean onItemLongClick(AdapterView<?> l, View v, int pos, long id) {
Log.i(DEBUG_TAG, "onItemLongClick");
if (WeatherData.getSingleton(getActivity().getApplication()).getLocCodes().size() > 1)
showDeleteAlertDialog(pos);
return false;
}
回答1:
Set return value of onItemLongClick to true so that it consumes the entire action. Works like a charm!
来源:https://stackoverflow.com/questions/8406181/onlistitemclick-and-onitemlongclick-google-tv