Overview:
I have two pages in my program; the main page and the other page.
On the main page I have two buttons; one button switches to the other page and the Add button adds some values together.
On the other page I have a single button that brings me back to the main page.
Currently I’m able to switch between the two pages without issue.
My Issue:
When I first open the program I can click the Add button and it will add the values together. I can continue to change between the two pages without issue.
However, after I have switched pages, when I click the Add button, my program crashes.
Here is my java file.
package com.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
public class AswitchActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button enterScoreButton = (Button) findViewById(R.id.button1);
enterScoreButton.setOnClickListener(enterScoreButtonListener);
}
public OnClickListener enterScoreButtonListener = new OnClickListener()
{
@Override
public void onClick(View v1)
{
}
public int addEntireHole(int addedHoles) {
return (addedHoles);
}
};
//This section goes from the main page to the other page
public OnClickListener Startpage = new OnClickListener(){
public void onClick(View v2){
}
};
public void onCreate(View view){
Button buttonSwitchMain = (Button)findViewById(R.id.btnSwitch);
buttonSwitchMain.setOnClickListener(Startpage);
setContentView(R.layout.other);
}
//This section goes from the other page to the main page
public OnClickListener otherpage = new OnClickListener(){
public void onClick(View v3){
}
};
public void onCreate3(View view2){
Button buttontoMain = (Button)findViewById(R.id.btnBack);
buttontoMain.setOnClickListener(otherpage);
setContentView(R.layout.main);
}
}
In your method
onCreate3, after callingsetContentViewyou should callonce again.