摘要页面和传递意图
Summary page and passing intents
我有一种形式,用户必须在其中写入一些信息并发送到 mysql 数据库。我现在尝试的是制作新的 activity ,在用户提交表单后加载并显示他刚刚提交的内容 - 摘要页面。
在这个 Activity 中,我从之前的 activity 中获取所有信息,并且用户将数据发送到数据库。然后我尝试将信息传递给 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>
现在 textview
的结果都是 NULL
。有人可以帮忙吗?
您在启动 activity 时正在创建新意图。好像出错了。
而不是
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);
如果您有任何疑问,请发表评论。
问题是您没有在调用开始 activity 之前首先 activity 将 bundle 设置为 activity
顺便初始化包变量
Bundle extrabundle = new Bundle();
我有一种形式,用户必须在其中写入一些信息并发送到 mysql 数据库。我现在尝试的是制作新的 activity ,在用户提交表单后加载并显示他刚刚提交的内容 - 摘要页面。
在这个 Activity 中,我从之前的 activity 中获取所有信息,并且用户将数据发送到数据库。然后我尝试将信息传递给 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>
现在 textview
的结果都是 NULL
。有人可以帮忙吗?
您在启动 activity 时正在创建新意图。好像出错了。
而不是
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);
如果您有任何疑问,请发表评论。
问题是您没有在调用开始 activity 之前首先 activity 将 bundle 设置为 activity
顺便初始化包变量
Bundle extrabundle = new Bundle();