我有EditText
用户写入金额。然后,当他们转到下一个Activity
时显示的数量与其他TextViews
。
这是Button
:
/** Called when the user clicks the Deposit button */
public void bnkDepBtn(View view) {
Intent intent = new Intent(BankDeposit.this, BankDepositConfirm.class);
EditText editText = (EditText) findViewById(R.id.bnk_dep_amount);
String DepAmount = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, DepAmount);
startActivity(intent);
finish();
}
然后这是下一个Activity
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class BankDepositConfirm extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bank_deposit_confirm);
// Get the message from the intent
Intent intent = getIntent();
String DepAmount = intent.getStringExtra(BankDeposit.EXTRA_MESSAGE);
}
这是我要添加的xml
<TextView
android:id="@+id/bnk_dep_con_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/bank_dep_title" />
<TextView
android:id="@+id/bnk_dep_con_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_below="@+id/bnk_dep_con_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:text="@string/bank_dep_con_text" />
<TextView
android:id="@+id/bnk_dep_con_txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_below="@+id/bnk_dep_con_txt"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:text="@string/DepAmount" />
</RelativeLayout>
问题是
我无法让文字显示在应用中。如何使用新EXTRA_MESSAGE
中的Activity
数据,例如调用String
。
答案 0 :(得分:1)
你只是得到这样的价值......
String DepAmount = getIntent().getStringExtra(EXTRA_MESSAGE//Content);
TextView textview = (TextView) findviewByid(value);
textview.setText(DepAmount );
答案 1 :(得分:0)
在名为class的意图中使用它:
String a=getIntent().getExtras().getString(EXTRA_MESSAGE);
TextView tName = (TextView) findViewById(R.id.prev_pad_textView1);
tName.setText(a);