/ / change la propriété d'une disposition relative feild programaticaly - android, relativelayout

changer la propriété d'une disposition relative feild programaticaly - android, relativelayout

Je travaille sur une application Android.Dans mon application, j'ai modifié dynamiquement l'alignement de textview. Le textview est en mode relativelayout. ce qui suit est mon exemple de fichier XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/all"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
>
<TextView android:id="@+id/snt_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/Gold"
android:text="df"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:padding="3dp"/>
</RelativeLayout>

Et java j'ai fait ce qui suit

View vi = inflater.inflate(R.layout.smsconversationsent_row, null);
RelativeLayout nws=(RelativeLayout)vi.findViewById(R.id.all);
TextView   message=(TextView)vi.findViewById(R.id.snd_txt);
RelativeLayout.LayoutParams params=(RelativeLayout.LayoutParams)message.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
message.setLayoutParams(params);

Mais je reçois une exception nullpointer pour message.getlayoutparams (). Les pls m'aident à résoudre ce problème.

Réponses:

1 pour la réponse № 1

La raison de l’exception nullpointer est la suivante: "Vous essayez de trouver R.id.snd_txt, mais en disposition, vous avez snt_txt, il est donc impossible de trouver une vue avec snd_txt id, car elle n ’existe pas dans la mise en page.