このページは、レイアウト用ファイルに記述するコード例をまとめています。
指定した文字列を表示するのに使います。
<TextView
android:layout_width="wrap_content" …①
android:layout_height="wrap_content" …①
android:layout_marginTop="5dp" …②
android:layout_marginBottom="5dp" …②
android:text="これはTextViewです" …③
/>
補足
文字を入力するフィールドを作成します。
<EditText
android:id="@+id/edittext" …①
android:layout_width="fill_parent" …②
android:layout_height="wrap_content" …③
android:hint="薄いグレーの文字" …④
android:selectAllOnFocus="true" …⑤
補足
EditText txtmsg = (EditText) findViewById(R.id.edittext);
String msg = txtmsg.getText().toString();
※表示させるだけなら、txtmsg.getText()でいいが、この出力はStringタイプでないため、
Stringとして処理させたい場合は、上記のようにする。
チェックボックスを作成します。
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
補足はありません。TextViewやEditTextの説明を参照してください。
ボタンを作成します。
<Button
android:id="@+id/button"
android:text="ボタン"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
ラジオボタンを作成します。
<RadioButton
android:id="@+id/radiobutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/radiobutton" />
補足
選択ボックスを作成します。
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="@array/spinner_list" />
補足
選択された文字列の取得方法
選択可能な一覧を作成します。
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="@array/listview_list" />
補足はありません。