この内容は、ViewSwitcher を使用した2画面アプリ (1) : 画面部分の作成と画面切り替えテスト『メニューの作成』より続いています。ViewSwitcher 上で二つのレイアウトを作成し、ViewSwitcher のメソッドを使用してそのレイアウトを切り替えます。そのまま全てを一つの画面定義に記述してもいいのでが、そうすると2画面目の内容を『デザイナ』で確認する事ができません。 ですから、2画面目は別の画面定義で作成して、include で ViewSwitcher の中から呼び出すようにします。 activity_main.xml 画面の切り替えは、一般的には ViewAnimator クラスの showNext() と showPrevious() を使うのですが、実行するのがメニューなので、どこで実行しても正しい画面が表示されるように、setDisplayedChild(int whichChild) を使用します( whichChild は 0 かまたは 1 ) 多少無駄な動きは存在しますが、簡単に正しく動作するはずです。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:padding="16dp"> <ViewSwitcher android:id="@+id/viewSwitcher" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> <include android:id="@+id/entry" layout="@layout/entry" android:layout_width="match_parent" android:layout_height="match_parent"/> </ViewSwitcher> </LinearLayout>
entry.xml editTextCode と textViewCode と は、社員マスタのキー部分に使用します。機能としては、修正処理と新規登録処理の二つあるので、それぞれ editTextCode と textViewCode を使い、使用しないほうは setVisibility(View.GONE); で非表示にします
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textViewCode" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="4dp" android:textSize="30sp"/> <EditText android:id="@+id/editTextCode" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPersonName"/> <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPersonName"/> <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPersonName"/> <Button android:id="@+id/buttonUpdate" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="更新"/> </LinearLayout>
|
【2017 Android Studioの最新記事】
- 別に納品するわけでは無いので、Android の ListView のカスタマイズなんてこれで十分でしょ / TestArrayAdapter バージョン2
- Java : Class 構造より、update 文を作成する
- ViewSwitcher を使用した2画面アプリ (5) : SQLiteデータを更新する
- ViewSwitcher を使用した2画面アプリ (4) : SQLiteデータをインポートしてリストビューに表示する
- Android Studio にインポートして使用する SQLite データベースを MDB より作成する VBScript
- ViewSwitcher を使用した2画面アプリ (3) : 画面部分の作成と画面切り替えテスト『画面をコントロールする Helper クラスの作成』
- ViewSwitcher を使用した2画面アプリ (1) : 画面部分の作成と画面切り替えテスト『メニューの作成』
- OkHttp を使用した HttpAccess クラスで Web 上の 画像をダウンロードして表示するテンプレート
- OkHttp を使用した HttpAccess クラスで Web 上の PHP アプリに対してファイルをアップロードするテンプレート
- OkHttp を使用した HttpAccess クラスで Web 上の掲示板に投稿(POST)するテンプレート
- OkHttp を使用した HttpAccess クラスで Web 上のデータを取得(GET)して ListView を表示するテンプレート
- Okhttp を使用した、GET、POST、ファイルアップロードを楽に実装できる HttpAccess クラス
- Android の assets フォルダーに保存した 400x320 の画像ファイルの扱い
- Android の drawable フォルダーに保存した 400x320 の画像ファイルの6種類の扱いと Density
- Android での保存用テキストデータの扱いを okio で簡素化する
- Android 6.0 : テストの為の Runtime Permission の対応を自動化するテンプレート
- Android Studio : Runtime Permission 等の裏方作業を MainActivity にさせて、本来の処理は継承したサブクラスで行う( カメラを呼び出して画像を保存させ、I..
- Android 6.0 エミュレータで 複数の Runtime Permission の対応を簡潔に吸収するクラス( CheckMyPermission )
- Android 6.0 の Runtime Permission に対応する前に、AndroidManifest.xml に権限の記述の必要無いプライベートな書き込みで情報を収集する
- Android Studio : エミュレータで Notification(通知)のテスト