I'm currently learning some android for a school project and I can't figure out the way to set text dynamically 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 apretiated... 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>
By not working I mean the text shown does not change at any moment...
Well,
@+id/listaVista
ListView is drawn after@+id/texto
and on top of it. So change in ListView from:to:
Also, since the list is drawn after textview, I find it dangerous to have
android:layout_alignRight="@+id/listaVista"
in TextView. So remove it and find another way of aligning.EDIT Taking a second look at your layout I think this is what you really want to have:
I had a similar problem. It turns out I had two TextView objects with the same ID. They were in different view files and so Eclipse did not give me an error. Try to rename your id in the TextView and see if that does not fix your problem.
in your activity_main.xml paste this code:
and go to res folder->values->strings.xml paste the below code with the code that already exists:
the above code means that you have created a textview with id:name(android:id="@+id/name") and assigned that textview to a string with an identifier name(android:text="@string/name") in strings.xml your using that identifier name to assign the text,
Try This:
Ensure you import TextView.
In layout file.
In Activity
In XML file,
In Java Activity file,