Vargoth
Vargoth

Reputation: 5

Adding and intent to TextView

I have a EditText that the user writes an amount. Then when they go to the next Activity the amount it shown with other TextViews.

this the 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();
}

then this is the next 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);

}

and this is the xml i want to add it to

<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>

The problem is

I can't get the text to appear in the app. How do I use the EXTRA_MESSAGE data in the new Activity like calling a String.

Upvotes: 0

Views: 1963

Answers (2)

prakash
prakash

Reputation: 1413

use this in intent called class:

String a=getIntent().getExtras().getString(EXTRA_MESSAGE);
TextView tName = (TextView) findViewById(R.id.prev_pad_textView1);
tName.setText(a);

Upvotes: 0

Naveen Kumar Kuppan
Naveen Kumar Kuppan

Reputation: 1442

You just get the value like this....

   String DepAmount = getIntent().getStringExtra(EXTRA_MESSAGE//Content);
   TextView textview = (TextView) findviewByid(value);
   textview.setText(DepAmount );

Upvotes: 1

Related Questions