Android - Set text to TextView

0 votes

I'm presently learning Android for a school project, however I'm having trouble figuring out how to dynamically set text to a TextView.

Here is my code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_enviar_mensaje);
    err = (TextView)findViewById(R.id.texto);
    err.setText("Escriba su mensaje y luego seleccione el canal.");
}

This is currently not working and I can't find a way to make it work...

Any help will be much appreciated... Thank you for the time, José.

EDIT: Here is the activity_enviar_mensaje.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ...
    tools:context=".EnviarMensaje" >
    ...
    <TextView
        android:id="@+id/texto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/listaVista"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/listaVista"
        android:text="TextView" />
    ...
</RelativeLayout>

When I say something isn't working, I mean that the displayed text never changes.

Nov 10, 2022 in Android by Edureka
• 13,620 points
2,709 views

1 answer to this question.

0 votes

After discovering the views, you set the content view. Setting the content view first is advised.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_connection_info);
    TextView ssid = (TextView) findViewById (R.id.ssid);
    TextView ip = (TextView) findViewById (R.id.ipaddr);

    ssid.setText(getSsid());
    ip.setText(getIpAddr());
} 
answered Nov 10, 2022 by Edureka
• 12,690 points

Related Questions In Android

0 votes
1 answer

How to set my Activity as main activity in android?

The "intent-filter" in "AndroidManifest.xml" allows you to ...READ MORE

answered Nov 8, 2022 in Android by Edureka
• 13,620 points
2,382 views
0 votes
0 answers

Android logo as an emoji (symbol) to copy and paste in text form

To use it in text editors, I ...READ MORE

Nov 23, 2022 in Android by Ashwini
• 5,430 points
4,304 views
0 votes
0 answers

How to put a border around an Android TextView?

Is it possible to draw a border ...READ MORE

Nov 23, 2022 in Android by Ashwini
• 5,430 points
836 views
0 votes
0 answers

"unable to locate adb" using Android Studio

I've been attempting to test my software ...READ MORE

Sep 21, 2022 in Android by Edureka
• 13,620 points
645 views
0 votes
1 answer
0 votes
1 answer

Kotlin Convert Bitcoin value into Satoshi Value

java.lang.NumberFormatException: For input string: "45,586" This means ...READ MORE

answered Apr 12, 2022 in Blockchain by Soham
• 9,710 points
841 views
0 votes
1 answer

How to write the Bitcoin logo as text?

Create a string in strings.xml like the ...READ MORE

answered Apr 12, 2022 in Blockchain by Aditya
• 7,680 points
954 views
0 votes
0 answers

Making TextView scrollable on Android

The text I'm showing in a TextView ...READ MORE

Nov 23, 2022 in Android by Ashwini
• 5,430 points
512 views
0 votes
1 answer

How to open the Google Play Store directly from my Android application?

If you want to link to your ...READ MORE

answered Nov 7, 2022 in Android by Edureka
• 12,690 points
4,398 views
0 votes
1 answer

How to turn on front flash light programmatically in Android?

For this problem you should: Check whether the ...READ MORE

answered Nov 8, 2022 in Android by Edureka
• 12,690 points
1,687 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP