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 in Android by Edureka
• 12,390 points
44 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 by Edureka
• 10,880 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 in Android by Edureka
• 12,390 points
36 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 in Android by Ashwini
• 2,760 points
44 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 in Android by Ashwini
• 2,760 points
37 views
0 votes
0 answers

"unable to locate adb" using Android Studio

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

Sep 21 in Android by Edureka
• 12,390 points
103 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 in Blockchain by Soham
• 9,670 points
113 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 in Blockchain by Aditya
• 7,660 points
148 views
0 votes
0 answers

Making TextView scrollable on Android

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

Nov 23 in Android by Ashwini
• 2,760 points
16 views
0 votes
1 answer
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 in Android by Edureka
• 10,880 points
43 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