Je rencontre un problème lorsque mon texte ViewPager ne s'affiche pas lorsque je démarre mon application. Cependant, les textes finissent par montrer quand je glisse l'onglet. Je ne suis pas sûr du problème et j'aimerais que le texte apparaisse dès que ma demande commence. Toute aide serait appréciée! Merci.Le texte ne s'affiche pas sur ViewPager
activité Pays (activité principale)
package myapps.countryapp;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import static myapps.countryapp.R.id.pager;
public class CountriesActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_countries);
ViewPager viewPager = (ViewPager) findViewById(pager);
viewPager.setAdapter(new MyAdapter(getSupportFragmentManager()));
}
public class MyAdapter extends FragmentPagerAdapter {
final int PAGE_COUNT = 2;
//Create tab tiles.
private String tabTiles[] = new String[] {"Countries", "Map"};
Context context;
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
if(position == 0){
Fragment fragmentList = new Countries();
return fragmentList;
}else {
Countries fragmentList = new Countries();
return fragmentList;
}
}
@Override
public int getCount() {
return PAGE_COUNT;
}
@Override
public CharSequence getPageTitle(int position) {
return tabTiles[position];
}
}
}//end of class
Countries.java (fichier fragment)
package myapps.countryapp;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.support.v4.app.Fragment;
/**
* A simple {@link Fragment} subclass.
*/
public class Countries extends Fragment {
public Countries() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_countries, container, false);
return view;
}
}
activity_countries (XML PRINCIPAL FICHIER)
<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="fill_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="myapps.countryapp.CountriesActivity">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTabStrip
android:layout_width="match_parent"
android:layout_height = "40dp"
android:paddingTop = "4dp"
android:paddingBottom = "10dp"
android:layout_gravity = "top"
android:id = "@+id/pagerStrip">
</android.support.v4.view.PagerTabStrip>
</android.support.v4.view.ViewPager>
fragment_countries.xml
<FrameLayout 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" tools:context="myapps.countryapp.Countries">
<!-- TODO: Update blank fragment layout -->
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/MyListView">
</ListView>
</FrameLayout>
De quel texte parlez-vous? Le titre des onglets? –
Oui le titre des onglets –
duplication possible de [Texte dans PagerTabStrip ne s'affiche pas sur la 1ère vue] (http://stackoverflow.com/questions/32168726/text-in-pagertabstrip-not-displayed-upon-1st-view) – Krish