本文介绍了onListItemClick和onItemLongClick谷歌电视的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个当我做谷歌电视上长按,但是只有合适的一个被称为用在平板电脑上相同的code中的方法被调用。任何想法如何处理onItemLongClick不会对GoogleTV的触发onListItemClick?

  @覆盖
    公共无效onListItemClick(ListView中升,视图V,INT位置,长的id){
        Log.i(DEBUG_TAGonListItemClick);
        WeatherData.getSingleton(getActivity().getApplication()).setCurrentLocation$c$c(WeatherData.getSingleton(getActivity().getApplication()).getLoc$c$cs().get(position));
        getListView()setItemChecked(位置,真)。
    }    公共布尔onItemLongClick(适配器视图<> L,视图V,INT POS,长I​​D){
        Log.i(DEBUG_TAGonItemLongClick);
        如果(WeatherData.getSingleton(getActivity()getApplication())getLoc codeS()大小()方式> 1。)
            showDeleteAlertDialog(POS)
        返回false;
    }


onItemLongClick的解决方案

设置返回值为true,这样它消耗了整个行动。就像一个魅力!

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;
    }
解决方案

Set return value of onItemLongClick to true so that it consumes the entire action. Works like a charm!

这篇关于onListItemClick和onItemLongClick谷歌电视的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 21:25