我如何使用微调setOnItemLongClickListener如何使用、setOnItemLongClickListener

2023-09-06 02:52:36 作者:怀着恨意生活

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

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

第一步工作得很好(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

微调迭代仅500次,大眼萌生成效果超越StyleGAN,可在线试玩

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.

When the user simple click on an item I want to normal select it. 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.