Pergunta

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

    }


}
Foi útil?

Solução

you can set the OnClickListener to null like so

btnNext.setOnClickListener(null);

Outras dicas

I think you just want this method

button.setClickable(false);

To make a button grey and UnClickable

put android:enabled="false" in button tag

And using code button.setEnabled(false);

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top