Pass text value to another text (java)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yakovcohen94
    New Member
    • Jun 2021
    • 5

    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="@+i d/PersonName"
    android:layout_ width="match_pa rent"
    android:layout_ height="wrap_co ntent"
    android:ems="10 "
    android:textCol orHint="@color/black"
    android:backgro und="@android:c olor/transparent"
    android:text="N ame" />

    FirstActivity.j ava

    public class FirstActivity extends AppCompatActivi ty {
    TextView PersonName;

    @Override
    protected void onCreate(Bundle savedInstanceSt ate) {
    super.onCreate( savedInstanceSt ate);
    setContentView( R.layout.activi ty_first);

    PersonName = (TextView)findV iewById(R.id.Pe rsonName);

    PersonName.setO nClickListener( new View.OnClickLis tener() {
    @Override
    public void onClick(View v) {
    Intent p = new Intent(FirstAct ivity.this, SecondActivity. class);
    startActivity(p );
    }
    });
    }
    }

    In second activity i have a scrollview.

    activity_second .xml

    <ScrollView
    android:layout_ width="match_pa rent"
    android:layout_ height="match_p arent">

    <LinearLayout
    android:layout_ width="match_pa rent"
    android:layout_ height="wrap_co ntent"
    android:orienta tion="vertical" >

    <TextView
    android:id="@+i d/textView"
    android:layout_ width="match_pa rent"
    android:layout_ height="wrap_co ntent"
    android:text="F ather" />

    <TextView
    android:id="@+i d/textView2"
    android:layout_ width="match_pa rent"
    android:layout_ height="wrap_co ntent"
    android:text="M other" />
    </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.
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    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.

    Comment

    Working...