AndroidDevelopersのチュートリアルのHelloFormStuffのRadioButtonsを実行します。
【手順】
1.「Androidプロジェクトの作成方法」の手順で、「AndroidSample017-HelloFormStuffRadioButtons」といプロジェクトを作成。
※プロジェクトの設定は以下の通り。
2.「res/layout/main.xml」を以下の様に入力。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/radio_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:text="Red" />
<RadioButton
android:id="@+id/radio_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"
android:text="Blue" />
</RadioGroup>
</LinearLayout>
3.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
7.エミュレータが起動しロックを解除し、以下の様にアプリケーションが実行されれば成功です。
4.「HelloFormStuffRadioButtons.java」を以下の様に入力。
package com.example.androidsample017;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.Toast;
public class HelloFormStuffRadioButtons extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onRadioButtonClicked(View v) {
// Perform action on clicks
RadioButton rb = (RadioButton) v;
Toast.makeText(HelloFormStuffRadioButtons.this, rb.getText(),
Toast.LENGTH_SHORT).show();
}
}
5.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
6.「Androidプロジェクトの実行方法」の手順で、「Androidプロジェクト」を実行。以上です。
HelloFormStuff+RadioButtons-01.png)
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。