質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

タブ

コンテンツの上下左右に参照用のメニューを設けることで、複数の要素やページの表示を可能にするユーザーインターフェイスパターンのこと。メニューをクリックすると、一つの要素が可視化され、他の要素は見えなくなる。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

1回答

1346閲覧

Tab機能とBottom navigation機能の両立

s.sawai

総合スコア7

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

タブ

コンテンツの上下左右に参照用のメニューを設けることで、複数の要素やページの表示を可能にするユーザーインターフェイスパターンのこと。メニューをクリックすると、一つの要素が可視化され、他の要素は見えなくなる。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2020/04/26 15:43

編集2020/04/27 00:44

前提・実現したいこと

現在、android用のアプリを作りたいと思っていて、Bottom navigationで画面を切り替え、その切り替え後の画面によっては画面上部に設置したTabによってさらに画面を切り替えられるようにしたいと思っています。ただ、ビルドは通るのですがエミュレータ上では即強制終了となってしまい原因がわからず困っています。

該当のソースコード

Java

1public class MainActivity extends AppCompatActivity { 2 3 @Override 4 protected void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 setContentView(R.layout.activity_main); 7 BottomNavigationView navView = findViewById(R.id.nav_view); 8 // Passing each menu ID as a set of Ids because each 9 // menu should be considered as top level destinations. 10 AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder( 11 R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications) 12 .build(); 13 NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); 14 NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); 15 NavigationUI.setupWithNavController(navView, navController); 16 //以下、Tab 17 SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager()); 18 ViewPager viewPager = findViewById(R.id.view_pager); 19 viewPager.setAdapter(sectionsPagerAdapter); 20 TabLayout tabs = findViewById(R.id.tabs); 21 tabs.setupWithViewPager(viewPager); 22 FloatingActionButton fab = findViewById(R.id.fab); 23 24 fab.setOnClickListener(new View.OnClickListener() { 25 @Override 26 public void onClick(View view) { 27 Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 28 .setAction("Action", null).show(); 29 } 30 }); 31 32 } 33 34}

Java

1//activity_main.xml 2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 android:id="@+id/container" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 android:paddingTop="?attr/actionBarSize"> 8 9 <com.google.android.material.bottomnavigation.BottomNavigationView 10 android:id="@+id/nav_view" 11 android:layout_width="0dp" 12 android:layout_height="wrap_content" 13 android:layout_marginStart="0dp" 14 android:layout_marginEnd="0dp" 15 android:background="?android:attr/windowBackground" 16 app:layout_constraintBottom_toBottomOf="parent" 17 app:layout_constraintLeft_toLeftOf="parent" 18 app:layout_constraintRight_toRightOf="parent" 19 app:menu="@menu/bottom_nav_menu" /> 20 21 <androidx.fragment.app.FragmentContainerView 22 android:id="@+id/nav_host_fragment" 23 android:name="androidx.navigation.fragment.NavHostFragment" 24 android:layout_width="match_parent" 25 android:layout_height="match_parent" 26 app:defaultNavHost="true" 27 app:layout_constraintBottom_toTopOf="@id/nav_view" 28 app:layout_constraintLeft_toLeftOf="parent" 29 app:layout_constraintRight_toRightOf="parent" 30 app:layout_constraintTop_toTopOf="parent" 31 app:navGraph="@navigation/mobile_navigation" /> 32 33 <com.google.android.material.appbar.AppBarLayout 34 android:layout_width="match_parent" 35 android:layout_height="wrap_content" 36 app:layout_constraintTop_toTopOf="parent" 37 android:theme="@style/AppTheme.AppBarOverlay"> 38 39 <TextView 40 android:id="@+id/title" 41 android:layout_width="wrap_content" 42 android:layout_height="wrap_content" 43 android:gravity="center" 44 android:minHeight="?actionBarSize" 45 android:padding="@dimen/appbar_padding" 46 android:text="@string/app_name" 47 android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" /> 48 49 <com.google.android.material.tabs.TabLayout 50 android:id="@+id/tabs" 51 android:layout_width="match_parent" 52 android:layout_height="wrap_content" 53 android:background="?attr/colorPrimary" /> 54 </com.google.android.material.appbar.AppBarLayout> 55 56 <androidx.viewpager.widget.ViewPager 57 android:id="@+id/view_pager" 58 android:layout_width="match_parent" 59 android:layout_height="match_parent" 60 app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 61

追加情報(何かの判断材料になれば)

MainActivityの「//以下、Tab」と記載してある場所から下のものを追加してから今の状態になっています。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ludolf

2020/04/27 09:07

エラー文の記述をお願いしますー
s.sawai

2020/04/27 16:05

今回は自己解決することができました。お気に留めてくださりありがとうございました。
guest

回答1

0

自己解決

ご迷惑をおかけしました。
Tabで参照するFragmentの1つをextends ListFragmentにしており、それが原因でエラーを起こしていました。

投稿2020/04/27 16:02

s.sawai

総合スコア7

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問