findViewById ne marche pas dans onTabSelected
Bonjour
je suis nouveau en dev android et j'ai une petite question
j'ai fait un mix entre le tutoriel Android et le projet par défaut d'Android studio
et ça marche mais quand je switch entre les tab et que je cherche à mettre à jour un TextView
Code:
1 2 3 4 5 6 7
| public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
mViewPager.setCurrentItem(tab.getPosition());
TextView mMsg;
mMsg = (TextView) (findViewById(R.id.h_message));
mMsg.setText(mr.TownName); |
ne marche pas car mMsg est null !
pourquoi findViewById me retourne un null,
je signale que le id.h_message fait partie du fragment .xml
Code:
1 2 3 4 5 6 7 8 9
| <TextView
android:id="@+id/h_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dip"
android:padding="10dip"
android:gravity="center"
android:text="@string/main"
style="@style/Text.Normal" /> |
comment fait on pour acceder aux textview des fragments sélectionnés
Merci