Search code examples
javaandroidandroid-activity

ImageButton not doing anything on click - android


Im doing the front-end of my new app on android, and I came across with a problem. On my first Activity my button works fine and take the user to the second Activity, now the problem appear. When I click on another button to take me to a third Activity nothing happens.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ImageButton saldoButton = (ImageButton)findViewById(R.id.saldoButton);

    saldoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            setContentView(R.layout.activity_saldo);

        }
    });
}

now follow my xml of this button:

            <ImageButton
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:id="@+id/saldoButton"
            android:layout_column="2"
            android:background="?android:attr/selectableItemBackground"
            android:src="@drawable/test02" />

Anyone has a clue what is happening?


Solution

  • You have to start third activity

    saldoButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                 Intent i= new Intent(currentActivity.this,thirdActivity.class);
                 startActivity(i);
    
            }
        });