子フラグメントで親フラグメントのタッチイベントが実行される

子フラグメント上に設置したフローティングアクションボタンをタッチしても親フラグメントのリスナーが呼び出されてしまう事象が。。。
調査した結果、子フラグメントのxmlに仕掛けが必要との事

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragment_hoge"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/seashell"
    android:clickable="true"
    >

上記のようにxmlに「android:clickable=”true”」を設定する事で親フラグメントのイベントを無効化する事ができるらしい。

Android FragmentからFragmentへの画面遷移

fragmentからfragmentへの画面遷移は以下のコードで実現

// インスタンス作成
SettingFragment sf = new SettingFragment();
FragmentManager fm= getActivity().getSupportFragmentManager();
// 遷移先をリプレイス
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.host_fragment, sf);
transaction.commit();

引数を渡したい場合は以下の様にすればOK

// インスタンス作成
SettingFragment sf = new SettingFragment();
FragmentManager fm= getActivity().getSupportFragmentManager();
Bundle bundle = new Bundle();

// bundleを使用して値を設定し次画面へ渡す
// “key”は任意の名称を指定してOK(次画面でデータ受取時に必要)
bundle.putString(“key”, hoge);
sf.setArguments(bundle);

// 遷移先をリプレイス
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.host_fragment, sf);
transaction.commit();


Android Activity 画面遷移

アクティビティの画面遷移はインテント(Intent)を使用する。

今回はログイン画面⇒メインメニューへの画面遷移を作成しました。

次の2画面を用意。LoginActivity、MainActivity

LoginActivityに以下のコードを追加することで画面遷移ができる

// メインアクティビティへ遷移
Intent intent = new Intent(getApplication(), MainActivity.class);
startActivity(intent);

はずでしたが、マニフェストファイルにも仕掛けが必要

マニフェストファイルに開始時のアクティビティに加え、遷移先のアクティビティを追加

AndroidManifest.xml への記載例

<activity
android:name=".LoginActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
</activity>

Android × Firebase

https://firebase.google.com にアクセスしプロジェクト作成

AndroidStudioのコンソールでCLIをインストール
npm install -g firebase-tools

CLIのインストールが完了したら以下のコマンドで起動
firebase login

Allow Firebase to collect CLI usage and error reporting information?
と尋ねられるのでYesを選択

ここまでで準備完了!
ターミナルからfirebaseが使用可能になる

firebase init のコマンドで

 ######## #### ########  ######## ########     ###     ######  ########
 ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
 ######    ##  ########  ######   ########  #########  ######  ######
 ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
 ##       #### ##     ## ######## ########  ##     ##  ######  ########

がでてくるはず

次に静的サイトのホスティングを選択します
Hosting: Configure and deploy Firebase Hosting sites

次に作成済みのプロジェクトを選択します

以降はEnterキーで進めて問題なし
ルールのファイル名は何にするか?(database.rules.json)
サイトホスティングのディレクトリ名は?(public)
SinglePageApplicationように設定するか?(yes)

コンソール実行ディレクトリに以下のファイルが作成されている事を確認
./database.rules.json
./firebase.json
./public/index.html

サーバー起動
firebase serve

AndroidStudio3.5備忘録

プロジェクト作成時にナビゲーションドロワーアクティビティを選択した際に雛形が作成されるが、その雛形にバグがあるらしい。。。

メニューをタップしても画面遷移ができない。。。

どうやら自動生成されたactivity_main.xmlに問題があるようでした。

以下は自動生成されたソース
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</androidx.drawerlayout.widget.DrawerLayout>

ナビゲーションメニューのレイアウトを記述している個所はincludeの後に記述しなければならないらしい。。。

修正後のソース
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</androidx.drawerlayout.widget.DrawerLayout>

この変更を行う事で正常に画面遷移が行えるようになりました。。。