一、RatingBar
Activity代码
public class RatingBarDemoActivity extends Activity {
private RatingBar rb=null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
rb=(RatingBar)findViewById(R.id.ratingbar1);
rb.setOnRatingBarChangeListener(new ClickRatingBar());
}
//设置监听器
class ClickRatingBar implements RatingBar.OnRatingBarChangeListener{
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
// TODO Auto-generated method stub
Toast.makeText(RatingBarDemoActivity.this, rating+"", Toast.LENGTH_LONG).show();
}
}
}
Main.xml代码:
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<RatingBar
android:id="@+id/ratingbar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="0.5"
/>
</LinearLayout>