我如何使用微调setOnItemLongClickListener [英] How can I use spinner setOnItemLongClickListener

查看:693
本文介绍了我如何使用微调setOnItemLongClickListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使微调行为不同的方式,当用户点击一个项目很长一段时间。我有微调器的一些项目,我想两件事情。

  1. 当用户简单的点击我想正常的项目中选择。
  2. 当用户早就点击了一个项目我想显示对话框,包含编辑项选项,删除项目。

第一步工作得很好(ofcourse),但是当我试图做第二个任务,我不能作出微调产生longClicked事件。

下面是我的code:

  this.projectSpinner =(微调)this.findViewById(R.id.SpinnerProjects);
    this.projectSpinner.setLongClickable(真正的);

    this.projectSpinner.setOnItemLongClickListener(新AdapterView.OnItemLongClickListener(){
        公共布尔onItemLongClick(适配器视图<>为arg0,
                                       查看ARG1,
                                       INT ARG2,
                                       长ARG3){
            Toast.makeText(
                 AndroidTimeTrackerMainActivity.this,
                 长按,
                 Toast.LENGTH_SHORT).show(); //这敬酒不出来。
            返回false;
        }

    });
 

解决方案

微调目前不支持 OnItemLongClickListener

I am trying to make the Spinner behave different way when the user clicked on an item for a long time. I have spinner with some project and I want two things.

  1. When the user simple click on an item I want to normal select it.
  2. When the user have long clicked on an item I want to show dialog, with options like "Edit item", "Delete item".

The first step works well (ofcourse), but when I am trying to do the second task I can not make spinner to generate longClicked event.

Here is my code:

    this.projectSpinner = (Spinner) this.findViewById(R.id.SpinnerProjects);
    this.projectSpinner.setLongClickable(true);

    this.projectSpinner.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){
        public boolean onItemLongClick(AdapterView<?> arg0, 
                                       View arg1, 
                                       int arg2, 
                                       long arg3) {
            Toast.makeText(
                 AndroidTimeTrackerMainActivity.this, 
                 "Long click", 
                 Toast.LENGTH_SHORT).show(); // This toast doesn't show up.
            return false;
        }

    });

解决方案

The Spinner currently does not support OnItemLongClickListener.

这篇关于我如何使用微调setOnItemLongClickListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆