mardi 12 juillet 2016

Can't change TextView after Inflate

I'm trying to edit the text of a textview of an inflated TextView

    ViewGroup parent = (ViewGroup) findViewById(R.id.activity_1);
    View view = LayoutInflater.from(getApplication()).inflate(R.layout.activity_2, parent, false);
    TextView textView = (TextView) view.findViewById(R.id.textView);
    textView.setText("Hello");

But, even though textView is not null after inflating, any attempts to change it programatically fail. I can't setText on it or influence it at all.

activity_2.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/listviewlayout"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <TextView
        android:id="@+id/textView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </TextView>

</LinearLayout>

Aucun commentaire:

Enregistrer un commentaire