Pour mon application Android, j'ai dû définir une disposition particulière contenant trois TextView vides. Ensuite, je veux modifier le contenu de ces TextView et ensuite ajouter LinearLayout à un autre LinearLayout par programmation. Mon problème est que lorsque j'essaie de faire référence à un TextView dans ma mise en page interne, j'ai une exception de pointeur NULL.Accès à un TextView dans un LinearLayout
Ceci est ma mise en page intérieure
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3"
android:id="@+id/firstRowLinearLayout">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:textStyle="bold"
android:id="@+id/matchTextView"
android:background="#ffffff"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textStyle="bold"
android:id="@+id/resultTextView"
android:background="#ffffff"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:textStyle="bold"
android:id="@+id/quoteTextView"
android:background="#ffffff"
android:textColor="#000000" />
</LinearLayout>
Et voici le code où je tente d'accéder à la TextView dans cette mise en page:
LinearLayout couponLinearLayout = (LinearLayout) findViewById(R.id.couponLinearLayout); // outer layout
LinearLayout test = (LinearLayout) findViewById (R.id.firstRowLinearLayout); // layout to be added to the outer one
TextView first_field = (TextView) test.findViewById(R.id.matchTextView);
(R.id.resultTextView);
first_field.setText("TEST");
couponLinearLayout.addView(test);
En utilisant ce code je suis, comme je l'ai dit, une exception de pointeur NULL lorsque je définis le TextView. J'espère que vous pouvez m'aider!
où est votre id 'couponLinearLayout'? – Rustam
êtes-vous gonfler votre mise en page? –