Imp Pale
Imp Pale

Reputation: 111

How to use referencing? is it through using @id or need to declare global variable?

this is part of my main.xml

<TextView
    android:id="@id/infoname"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="35dp"
    android:text="Hi Name"
    android:textSize="25sp" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Welcome to Program"
    android:textAppearance="?android:attr/textAppearanceLarge" />

this is part of my editinfo.xml

<EditText
        android:id="@+id/infoname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:hint="3 to 10 characters" 
        android:layout_weight="1"/>

from editing the id/infoname from edit text(for example input is MyName) how could i do something like Hi MyName from the content main.xml thanks :)

Upvotes: 0

Views: 163

Answers (1)

bschultz
bschultz

Reputation: 4254

You're trying to change the text property of your EditText programmatically?

In your Java file's onCreate:

EditText yourEditText = (EditText)findViewById(R.id.yourEditText);
yourEditText.setText("MyName");

You're getting a reference to your EditText object and setting the text property.

Upvotes: 1

Related Questions