Skip to content Skip to sidebar Skip to footer

How To Pass Value Of One Textview To Another Textview In Different Activity

Possible Duplicate: How to pass object from one activity to another in Android I have two activities Activity 1 and Activity 2. For these two activities, I have two XML layout 1.

Solution 1:

INTENT Use Intent to pass data, putExtra() will allow you to put data

ActivityA

Intent myIntent = newIntent(ActivityA.this, Activityb.class);
myIntent.putExtra("key", "value");
startActivity(myIntent); 

ActivityB

IntentmyIntent= getIntent(); // this is just for example purpose
myIntent.getExtra("key");

Solution 2:

First Activity -

Buttonbtn= (Button)findViewById(R.id.button1);
b.setOnClickListener(newView.OnClickListener() 
{
        @OverridepublicvoidonClick(View v) {
            // TODO Auto-generated method stubStringpassingdata= textview.getText().toString();
                        Intenti=newIntent(Activity1.this, Activity2.class);
                        Bundleb=newBundle();
                        b.putString("Key", passingdata);
                        i.putExtras(b);
                        startActivity(i);
        }
    });

Second Activity -

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second);
    Bundleb= getIntent().getExtras();
    Stringreceivingdata= b.getStringExtra("Key");
    TextViewtv= (TextView)findViewById(R.id.secondtext);
    tv.setText(receivingdata);
}

Solution 3:

try this using Intent:

In Activity 1 on Button Click:

Intent intent = newIntent(Activityone.class, Activitytwo.class);   
intent.putExtra("value2","world");  
startActivity(intent); 

In Activity 2:

@Override  
protectedvoid onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    String value1 = super.getIntent().getExtras().getString("value1");  
    myTextView.setText("value1: " + value1 + ");  
}

Solution 4:

While starting new activity in your button click write below code

Intent intent = newIntent();
intent.putExtra("TextValue", text1.getText().toString());
intent.setClass(Activity1.this, Activity2.class);
startActivity(intent);

In your Activity2 in onCreate()

Strings= getIntent().getStringExtra("TextValue");

Solution 5:

You need to put extra parameters on your intent. Watch this article.

Post a Comment for "How To Pass Value Of One Textview To Another Textview In Different Activity"