How to make a button unclickable [duplicate]

ε祈祈猫儿з 提交于 2019-12-10 16:44:59

问题


So right now i am having trouble making the next button unclickable when it is on the last page of the activity. As of right now it goes back to the first screen. How do i make it so that it know when to grey out the button or make it unclickable when the user gets to the last screen.

Here is my code:

public class ReadingActivity extends Activity implements OnClickListener {

    private ViewFlipper viewFlipper;
    Button btnNext, btnPrev;
    private float lastX;

    /** Called when the activity is first created */

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reading);
        viewFlipper=(ViewFlipper)findViewById(R.id.view_flipper);
        btnNext=(Button)findViewById(R.id.btnNext);
        btnPrev=(Button)findViewById(R.id.btnPre);


        btnNext.setOnClickListener(this);
        btnPrev.setOnClickListener(this);

        btnNext.setEnabled(true);
    }



    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

        switch(arg0.getId()){
        case R.id.btnNext:
            viewFlipper.setInAnimation(this, R.anim.in_from_right);
            viewFlipper.setOutAnimation(this, R.anim.out_to_left);
            viewFlipper.showNext();
            break;
        case R.id.btnPre:
            viewFlipper.setInAnimation(this, R.anim.in_from_left);
            viewFlipper.setOutAnimation(this, R.anim.out_to_right);
            viewFlipper.showPrevious();
            break;
        }

    }


}

回答1:


you can set the OnClickListener to null like so

btnNext.setOnClickListener(null);



回答2:


I think you just want this method

button.setClickable(false);



回答3:


To make a button grey and UnClickable

put android:enabled="false" in button tag

And using code button.setEnabled(false);



来源:https://stackoverflow.com/questions/19625569/how-to-make-a-button-unclickable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!