/    Sign up×
Community /Pin to ProfileBookmark

Pass text value to another text (java)

I want to build a category list scrollview in android studio using java. I having truble to understand how to pass value from TextView to anthor TextView with same value in other activity.
activity_first.xml

“`
<TextView
android:id=”@+id/PersonName”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:ems=”10″
android:textColorHint=”@color/black”
android:background=”@android:color/transparent”
android:text=”Name” />
“`

FirstActivity.java

“`
public class FirstActivity extends AppCompatActivity {
TextView PersonName;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);

PersonName = (TextView)findViewById(R.id.PersonName);

PersonName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent p = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(p);
}
});
}
}
“`

In second activity i have a scrollview.
activity_second.xml

“`
<ScrollView
android:layout_width=”match_parent”
android:layout_height=”match_parent”>

<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:orientation=”vertical” >

<TextView
android:id=”@+id/textView”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”Father” />

<TextView
android:id=”@+id/textView2″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”Mother” />
</LinearLayout>
</ScrollView>
“`

in activity_second.xml when I press on TextView it will return me with the value Father (id:textView) to the FirstActivity and change the TextView (id: PersonName) to father and if I’ll do it with value mother (id:textView2) it will do same action and return me to FirstActivity.

to post a comment
Java

1 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumJul 05.2021 — Please use code tags: `your code here` or triple backticks when posting code.

I edited your posting accordingly.
×

Success!

Help @Yakovcohen93 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...