【发布时间】:2012-02-22 19:44:52
【问题描述】:
概述: 我的程序中有两页;主页和其他页面。
在主页上我有两个按钮;一个按钮切换到另一页,添加按钮将一些值添加在一起。
在另一个页面上,我有一个按钮可以让我回到主页。
目前我可以毫无问题地在两个页面之间切换。
我的问题: 当我第一次打开程序时,我可以单击“添加”按钮,它会将值添加在一起。我可以继续在两个页面之间切换而不会出现问题。 但是,在我切换页面后,当我点击添加按钮时,我的程序崩溃了。
这是我的 java 文件。
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);
}
}
【问题讨论】: