OnItemClickListener使用OnItemLongClickListener

时间:2012-11-19 11:32:47

标签: android

我如何同时使用OnItemClickListener和OnItemLongClickListener,或者只是在列表视图中禁用longclick? 我重写了OnItemLongClickListener,当我在onItemLong上返回true时,longclick将禁用但OnItemClickListener将不再响应。

DailyReportList.setOnItemLongClickListener(new OnItemLongClickListener(){ 
        @Override   
    public boolean onItemLongClick(AdapterView parentView, View childView, int position, long id) {

        return true;}});


    registerForContextMenu(DailyReportList);
    DailyReportList.setOnItemClickListener(new OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            arg1.showContextMenu();
            FillTxtWithListItems(arg1);

        }});

2 个答案:

答案 0 :(得分:2)

如果要禁用onClick或onLongClick,只需取消选中/检查layout xml properties中的功能即可。查找有关如何禁用它的图像.. enter image description here

enter image description here

答案 1 :(得分:1)

如果您不想要长时间点击监听器或上下文菜单,请不要设置任何内容,也不要调用registerForContextMenu()。列表本身没有这些。