468,740 Members | 2,035 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,740 developers. It's quick & easy.

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.
3 Weeks Ago #1
1 4456
dev7060
450 Expert 256MB
I want to build a category list scrollview in android studio using java.
You may want to use a ListView.

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.
Add on-click event listener with the LinearLayout. When the event triggers, get the id (or text) and pass the value to FirstActivity using an intent.
3 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Treetop | last post: by
4 posts views Thread by Maya | last post: by
13 posts views Thread by pauldepstein | last post: by
7 posts views Thread by Brad Pears | last post: by
reply views Thread by zhoujie | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.