情况如下:我有 3 个活动,第一个包含一个按钮和一个 TextView,它显示了该按钮的点击次数。第二个活动看起来相同,它必须接收第一个活动的点击次数,如果点击了自己的按钮,则将其增加 +1,然后将其传递给第三个活动,依此类推。如何管理这个?提前致谢。
因此,如果我在第一个活动中单击按钮,第二个活动应该显示“1”,如果我在第二个活动中也单击按钮,第三个活动应该显示“2”
表 1:
public class Tab1 extends Activity {
ImageButton button1;
int count = 0;
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab1);
button1 = (ImageButton)findViewById(R.id.button2);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent firstIntent = new Intent(Tab1.this, Tab2.class);
startActivity(firstIntent);
TextView t = (TextView)findViewById(R.id.t);
t.setText("score: " + ++count +"/18");
finish();
}
});
} }
表 2:
public class Tab1 extends Activity {
ImageButton button1;
int count = 0;
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab2);
button1 = (ImageButton)findViewById(R.id.button2);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent firstIntent = new Intent(Tab1.this, Tab2.class);
startActivity(firstIntent);
TextView t = (TextView)findViewById(R.id.t);
t.setText("score: " + ++count +"/18");
finish();
}
});
} }
Tab3 看起来一样