Victor Laerte
Victor Laerte

Reputation: 6556

Is There a way to fire KeyEvent.KEYCODE_BACK to a customized button?

I want to create another back button in my application. To do that I could use the finish method but the Action that I need already exists in Android KeyEvent.KEYCODE_BACK, than I was trying just to fire this event on my clicklistener, there's a way to do that?

Button btnVoltar = (Button) findViewById(R.id.btnVoltar);

    btnVoltar.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            // HERE I WANT TO USE KeyEvent.KEYCODE_BACK
        }
    });

Upvotes: 0

Views: 629

Answers (1)

Viswanath Lekshmanan
Viswanath Lekshmanan

Reputation: 10083

Try this override onbackpressed and invoke it on your click

        @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
    }
  btnVoltar.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            onBackPressed();
        }
    });

Upvotes: 1

Related Questions