私は3つの異なるタブを使用するアプリケーションを作成しようとしています。私はこのビデオチュートリアルに続き、開始する:Youtube - Android Tab Tutorial [Android Studio Tab Fragments] 私はアプリを作り、私の電話でそれをチェックアウトした。 3つのタブが表示され、正常に動作しています(私はそれらの間で切り替えることができます)。Android TabLayoutが表示されない
今私がする必要があったのは、さまざまなレイアウトにウィジェットを追加することだったので、私はそれを行い、アプリケーションを再構築してもう一度試しました。しかし、それはまったく同じように見えます。私はちょうど追加したコントロールが表示されません。
SectionsPageAdapter:
public class SectionsPageAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public void addFragment(Fragment fragment, String title){
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
public SectionsPageAdapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
}
Tab_Alarm:
public class Tab_Alarm extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_alarm,container,false);
return view;
}
}
MainActivity:ここ
コードです
public class MainActivity extends AppCompatActivity {
private SectionsPageAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSectionsPagerAdapter = new SectionsPageAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.container);
setupViewPager(mViewPager);
TabLayout tabLayout = (TabLayout)findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
}
private void setupViewPager(ViewPager viewPager){
SectionsPageAdapter adapter = new SectionsPageAdapter(getSupportFragmentManager());
adapter.addFragment(new Tab_Alarm(), "Alarm");
adapter.addFragment(new Tab_Countdown(), "Countdown");
adapter.addFragment(new Tab_Timer(), "Timer");
viewPager.setAdapter(adapter);
}
}
私は、各タブの1つのクラスを持っていますが、すべてのl
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/Layout_Main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/Layout_Container_List"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="vertical"
android:paddingBottom="25dp"
android:paddingTop="25dp"
app:layout_constraintBottom_toTopOf="@+id/Layout_Container_Buttons"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1">
<ListView
android:id="@+id/ListView_AlarmList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/Layout_Container_Buttons"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1">
<Button
android:id="@+id/btn_AddAlarm"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/add_alarm" />
<Button
android:id="@+id/btn_DeleteAlarm"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/delete_alarm" />
</LinearLayout>
を実行中にすべてのタブを空のまま:OOK(。異なるxmlファイルの点を除いて)同じ
ここで表示されないTabLayoutのための私のxmlファイルですアプリのうちの1つにもかかわらず、それにものを持っています。