AndroidDevelopersのチュートリアルのHelloFormStuffのRatingBarを実行します。
【手順】
1.「Androidプロジェクトの作成方法」の手順で、「AndroidSample019-HelloFormStuffRatingBar」といプロジェクトを作成。
※プロジェクトの設定は以下の通り。
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" >
<RatingBar
android:id="@+id/ratingbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0" />
</LinearLayout>
3.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
7.エミュレータが起動しロックを解除し、以下の様にアプリケーションが実行されれば成功です。
4.「HelloFormStuffToggleButton.java」を以下の様に入力。
package com.example.androidsample019;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.Toast;
public class HelloFormStuffRatingBar extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar);
ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
Toast.makeText(HelloFormStuffRatingBar.this, "New Rating: " + rating,
Toast.LENGTH_SHORT).show();
}
});
}
}
5.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
6.「Androidプロジェクトの実行方法」の手順で、「Androidプロジェクト」を実行。以上です。
HelloFormStuff+RatingBar-01.png)
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。