Android-radiobutton-control
提供:Dev Guides
Android-RadioButtonコントロール
'_RadioButtonには、チェック済みまたは未チェックの2つの状態があります。これにより、ユーザーはセットから1つのオプションを選択できます。_
ラジオボタン
例
この例では、簡単な手順で、リニアレイアウトとRadioButtonを使用して独自のAndroidアプリケーションを作成する方法を示します。
Step | Description |
---|---|
1 | You will use Android studio to create an Android application and name it as My Application under a package com.example.saira_000.myapplication as explained in the Hello World Example chapter. |
2 | Modify src/MainActivity.java file to add a click event. |
2 | Modify the default content of res/layout/activity_main.xml file to include Android UI control. |
3 | Android studio takes care of default constants so no need to declare default constants at string.xml file |
4 | Run the application to launch Android emulator and verify the result of the changes done in the application. |
以下は、変更されたメインアクティビティファイル src/MainActivity.java の内容です。 このファイルには、基本的な各ライフサイクルメソッドを含めることができます。
'_以下の例では、abcはfinddevguidesのイメージを示しています_
以下は res/layout/activity_main.xml ファイルの内容です-
以下は、これらの新しい定数を定義する res/values/strings.xml の内容です-
以下は、 AndroidManifest.xml のデフォルトのコンテンツです-
ユーザーがラジオボタンのいずれかを選択した場合、Toastメッセージに同じ名前を付ける必要があります。 たとえば、ユーザーがJAVAを選択した場合、JAVAとしてトーストメッセージが表示されます
運動
プログラミング時にRadioButtonの異なる属性を使用して上記の例を試して、RadioButtonのルックアンドフィールを変更することをお勧めします。 編集可能にし、フォントの色、フォントファミリ、幅、textSizeなどに変更して、結果を確認してください。 1つのアクティビティで複数のRadioButtonコントロールを使用して上記の例を試すこともできます。