Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a button unclickable [duplicate]

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;
        }

    }


}
like image 677
Dan Avatar asked Mar 21 '23 21:03

Dan


1 Answers

you can set the OnClickListener to null like so

btnNext.setOnClickListener(null);
like image 182
JRowan Avatar answered Mar 24 '23 11:03

JRowan