[英]using multiple intent in an activity
I have 6 page that page 1-5 on a button click sends an string to page 6 and page 6 shows them in textviews using intent but when i reach page 6 it shows only the last string in all of textviews 我有6页,单击按钮的第1-5页将字符串发送到第6页,而第6页使用意图在textview中显示了它们,但是当我到达第6页时,它仅显示了所有textview中的最后一个字符串
page 1 第1页
public class page1 extends ActionBarActivity {
public static final String EXTRA_MESSAGE="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page1);
}
public void cow (View view){
startActivity(new Intent(this, page2.class));
Intent intent = new Intent(this, resault.class);
String message = "پیشرو بودن";
intent.putExtra(EXTRA_MESSAGE, message);
}
public void horse (View view){
startActivity(new Intent(this, page2.class));
Intent intent = new Intent(this, resault.class);
String message = "خانواده";
intent.putExtra(EXTRA_MESSAGE, message);
}
public void pig (View view){
startActivity(new Intent(this, page2.class));
Intent intent = new Intent(this, resault.class);
String message = "پول";
intent.putExtra(EXTRA_MESSAGE, message);
}
public void tiger (View view){
startActivity(new Intent(this, page2.class));
Intent intent = new Intent(this, resault.class);
String message = "غرور و افتخار";
intent.putExtra(EXTRA_MESSAGE, message);
}
public void sheep (View view){
startActivity(new Intent(this, page2.class));
Intent intent = new Intent(this, resault.class);
String message = "عشق";
intent.putExtra(EXTRA_MESSAGE, message);
}
}
to page 4 its the same but i changed the numbers 至第4页相同,但我更改了数字
page5 第5页
public class page5 extends ActionBarActivity {
public static final String EXTRA_MESSAGE5="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page5);
}
public void cow (View view){
Intent intent5 = new Intent(this, resault.class);
String message5 = "پیشرو بودن";
intent5.putExtra(EXTRA_MESSAGE5, message5);
startActivity(intent5);
}
public void horse (View view){
Intent intent5 = new Intent(this, resault.class);
String message5 = "خانواده";
intent5.putExtra(EXTRA_MESSAGE5, message5);
startActivity(intent5);
}
public void pig (View view){
Intent intent5 = new Intent(this, resault.class);
String message5 = "پول";
intent5.putExtra(EXTRA_MESSAGE5, message5);
startActivity(intent5);
}
public void tiger (View view){
Intent intent5 = new Intent(this, resault.class);
String message5 = "غرور و افتخار";
intent5.putExtra(EXTRA_MESSAGE5, message5);
startActivity(intent5);
}
public void sheep (View view){
Intent intent5 = new Intent(this, resault.class);
String message5 = "عشق";
intent5.putExtra(EXTRA_MESSAGE5, message5);
startActivity(intent5);
}
}
receiver page (page 6) 收件人页面(第6页)
public class resault extends ActionBarActivity {
TextView ch1;
TextView ch2;
TextView ch3;
TextView ch4;
TextView ch5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resault);
// choise1
ch1 = (TextView) findViewById(R.id.choice1);
Intent intent;
intent = getIntent();
String message = intent.getStringExtra(page1.EXTRA_MESSAGE);
ch1.setText(message);
// choise2
ch2 = (TextView) findViewById(R.id.choice2);
Intent intent2;
intent2 = getIntent();
String message2 = intent2.getStringExtra(page2.EXTRA_MESSAGE2);
ch2.setText(message2);
// choise3
ch3 = (TextView) findViewById(R.id.choice3);
Intent intent3;
intent3 = getIntent();
String message3 = intent3.getStringExtra(page3.EXTRA_MESSAGE3);
ch3.setText(message3);
// choise4
ch4 = (TextView) findViewById(R.id.choice4);
Intent intent4;
intent4 = getIntent();
String message4 = intent4.getStringExtra(page4.EXTRA_MESSAGE4);
ch4.setText(message4);
// choise5
ch5 = (TextView) findViewById(R.id.choice5);
Intent intent5;
intent5 = getIntent();
String message5 = intent5.getStringExtra(page5.EXTRA_MESSAGE5);
ch5.setText(message5);
}
}
really really thank you for helping 真的非常感谢您的帮助
You need to adjust your logic. 您需要调整逻辑。 For example in page 6:
例如在第6页中:
public class resault extends ActionBarActivity {
public final static String EXTRA_MASSAGE = "massage";
public final static String EXTRA_PAGE = "page";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resault);
String text = getIntent().getStringExtra(EXTRA_MASSAGE);
if (text != null ) {
int page = getIntent().getIntExtra(EXTRA_PAGE, -1);
switch (page) {
case 1:
((TextView) findViewById(R.id.choice1)).setText(text);
break;
case 2:
((TextView) findViewById(R.id.choice2)).setText(text);
break;
case 3:
((TextView) findViewById(R.id.choice3)).setText(text);
break;
case 4:
((TextView) findViewById(R.id.choice4)).setText(text);
break;
case 5:
((TextView) findViewById(R.id.choice5)).setText(text);
break;
}
}
}
}
Then you do in page 3 for example: 然后,例如在第3页中执行:
Intent intent = new Intent(this, resault.class);
String message = "خانواده";
intent.putExtra(Result.EXTRA_PAGE, 3);
intent.putExtra(Result.EXTRA_MASSAGE, message);
startActivity(intent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.