I am currently developing an android app. I have 4 layouts in my app(1 main layout and 3 sub layouts). In my main layout I am using three imagebuttons and if each button is clicked it starts an activity. i.e., when a button is clicked it transitions over to the next layout. I used the onClicklistener() method to handle the event when the button is clicked. The problem is that when the first button is clicked it changes to the next layout successfully but when the other two buttons are clicked the app force closes. In each sub layout I use a listview to display some content. Here is the code for the mainactivity:
public class MainactivityActivity extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mainactivity);
ImageButton m1 = (ImageButton) findViewById(R.id.imageButton1);
ImageButton m2 = (ImageButton) findViewById(R.id.imageButton2);
ImageButton m3 = (ImageButton) findViewById(R.id.imageButton3);
m1.setOnClickListener(this);
m2.setOnClickListener(this);
m3.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.imageButton1:
Intent intent= new Intent(MainactivityActivity.this,Inspire.class);
startActivity(intent);
break;
case R.id.imageButton2:
Intent inte = new Intent(MainactivityActivity.this,Love.class);
startActivity(inte);
break;
case R.id.imageButton3:
Intent inten = new Intent(MainactivityActivity.this,Other.class);
startActivity(inten);
break;
default:
}
}}
I also added the value android:onclick="onClick" in the xml layout for each button. when the first image button it transfers to the next layout but when the other image buttons are clicked my app force closes and I get errors. I tried googling it but I couldn't find a perfect solution. Please help me solve this. Thanks in advance