我有一个表单,用户必须写一些信息并发送到mysql数据库。我现在尝试的是创建一个新活动,在用户提交表单后加载并显示他刚刚提交的内容 - 摘要页面。
在此活动中,我获取了之前活动的所有信息,并且用户将数据发送到DB。然后我尝试将信息传递给Summary.class
btnFinish = (Button) findViewById(R.id.btnFinish);
btnFinish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle extras = getIntent().getExtras();
if (extras != null) {
Name = getIntent().getExtras().getString("Name");
Email = getIntent().getExtras().getString("Email");
}
new SummaryAsyncTask().execute((Void) null);
Intent newActivity = new Intent(TableInformation.this, Summary.class);
newActivity.putExtra("Name", Name);
newActivity.putExtra("Email", Email);
Log.d("Information to summary", Name + " " + Email);
startActivity(new Intent(Information.this, Summary.class));
}
这就是我目前在Summary.class
String getName;
String getEmail;
TextView nameOfPerson, emailOfPerson;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.summary);
Bundle extras = getIntent().getExtras();
if (extras != null) {
getName = getIntent().getExtras().getString("Name");
getEmail = getIntent().getExtras().getString("Email");
}
((TextView)findViewById(R.id.nameOfPerson)).setText(getName+"");
((TextView)findViewById(R.id.emailOfPerson)).setText(getEmail+"");
}
summary.xml
包含
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/nameOfPerson"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="75dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/emailOfPerson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
现在,NULL
上的结果为textview
。任何人都可以帮忙吗?
答案 0 :(得分:1)
您正在开始活动时创建新意图。这似乎是一个错误。
而不是
Intent newActivity = new Intent(TableInformation.this, Summary.class);
newActivity.putExtra("Name", Name);
newActivity.putExtra("Email", Email);
Log.d("Information to summary", Name + " " + Email);
startActivity(new Intent(Information.this, Summary.class));
这样做
Intent newActivity = new Intent(TableInformation.this, Summary.class);
newActivity.putExtra("Name", Name);
newActivity.putExtra("Email", Email);
Log.d("Information to summary", Name + " " + Email);
startActivity(newActivity);
如果您有任何疑问,请发表评论。
答案 1 :(得分:1)
问题是在调用start活动之前,您没有在第一个活动上将bundle设置为activity
顺便初始化bundle变量就好了
Bundle extrabundle = new Bundle();