I can not put two different actions to two ImageButton
different in the same MainActivity
, putting the function only to the first ImageButton
, if it works, but when putting the function to the second, I get:
error: reached end of file while parsing
package prueba.otrointento;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
import android.widget.ImageButton;
import static prueba.otrointento.R.id.btn1;
public class MainActivity extends AppCompatActivity {
ImageButton btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (ImageButton) findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent boton1 = new Intent(MainActivity.this, Main2Activity.class);
startActivity(boton1
);
}
ImageButton btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn2 = (ImageButton) findViewById(R.id.btn2);
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent boton2 = new Intent(MainActivity.this, Main2Activity.class);
startActivity(boton2
);
}
});
}
}