Pass text value to another text (java)

Discussion in 'Programming' started by Yakov Cohen, Jul 4, 2021.

  1. #2
    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:eek:rientation="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.
     
    Yakov Cohen, Jul 4, 2021 IP