3

I have a few imageview which have onclicklistener. If I press one (not release), I can press click others or I can click them same time. I do not want it. Everytime when I press one of them others should be disable to click.

imageview1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                getMethod();

            }
        });

I guess, I tried setClickable(false); but it did not work properly, if I clicked one button after that it worked.

4

3 回答 3

3
//button on which press u want to disable others
button1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
              button2.setEnabled(false);  //button which u want to disable
              button3.setEnabled(false);  //button which u want to disable
            }
        });

//update fixed a spelling error
于 2013-05-28T08:55:47.780 回答
3

尝试使用onTouchListener代替onClickListener并调用setEnabled(false);那里的其他视图。这是一个相当基本的例子:

OnTouchListener onTouchListener = new OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            imageView1.setEnabled(false);
            imageView2.setEnabled(false);
        }
        return true;
    }
};

然后将其应用于图像视图:

imageView1.setOnTouchListener(onTouchListener);

那应该行得通。有一件事是,虽然无论如何你只能按下一个按钮,但在你放手后你也无法按下任何按钮 - 但是,你可以通过添加一些逻辑来解决这个问题视图实际上被点击了,或者如果用户触摸它,改变主意并溜走。(event.getAction() == MotionEvent.ACTION_DOWN)即使用户只是滚动,检查也将是真的。

于 2013-05-28T08:46:17.730 回答
1

尝试禁用按钮并

button.setEnable(false);

启用按钮

button1.setEnable(true);
于 2013-05-28T08:47:08.130 回答