Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable OnClickListerners

I am developing an app where the user has to match the image and corresponding name of it correctly.

My problem is when the user selects the image first and selects the wrong name it will display wrong answer and if he selects the answer it will be displayed correct answer.

The user should not have to re-select the image again

I have made the onClickListerner's null but it wont work some of my code is as follows,

    txt_tag[0] = (TextView) findViewById(R.id.txt_tag1);
    txt_tag[0].setOnClickListener(this);
    txt_tag[0].setTypeface(tf);

    txt_tag[1] = (TextView) findViewById(R.id.txt_tag2);
    txt_tag[1].setOnClickListener(this);
    txt_tag[1].setTypeface(tf);

    txt_tag[2] = (TextView) findViewById(R.id.txt_tag3);
    txt_tag[2].setOnClickListener(this);
    txt_tag[2].setTypeface(tf);

    txt_tag[3] = (TextView) findViewById(R.id.txt_tag4);
    txt_tag[3].setOnClickListener(this);
    txt_tag[3].setTypeface(tf);

    img[0] = (ImageButton) findViewById(R.id.img1);
    img[0].setOnClickListener(this);

    img[1] = (ImageButton) findViewById(R.id.img2);
    img[1].setOnClickListener(this);

    img[2] = (ImageButton) findViewById(R.id.img3);
    img[2].setOnClickListener(this);

    img[3] = (ImageButton) findViewById(R.id.img4);
    img[3].setOnClickListener(this);

    btn_nxt = (Button) findViewById(R.id.btn_next);
    btn_nxt.setOnClickListener(this);

and I have called an method inside that method where I have made all onClickListerner's null

txt_tag[0].setOnClickListener(null);
txt_tag[1].setOnClickListener(null);
txt_tag[2].setOnClickListener(null);
txt_tag[3].setOnClickListener(null);
img[0].setOnClickListener(null);
img[1].setOnClickListener(null);
img[2].setOnClickListener(null);
img[3].setOnClickListener(null);

Can anyone tell me where I am going wrong or any modifications I can do to it.

Thanks in advance

like image 914
Rithesh M Avatar asked Jan 19 '26 21:01

Rithesh M


1 Answers

Try using

       txt_tag[0].setClickable(false);
       txt_tag[1].setClickable(false);
       ..
       img[0].setClickable(false);
       img[1].setClickable(false);
       ..
like image 74
Rafiq Avatar answered Jan 21 '26 13:01

Rafiq