Super Copying blog informasi tentang teknologi, game, android, kesehatan, komputer dan adsense. Powered by Blogger.

Membuat Aplikasi Android Ratingbar


Kali ini kita akan membuat aplikasi widget android dengan menggambungkan semua widget yang sudah kita ketahui dan pelajari sebelumnya, tapi kita akan tambahkan dengan sebuah widget baru yaitu Ratingbar. Ratingbar  adalah vote dari user untuk memberikan nilai pada suatu objek untuk menentukan bagus atau tidaknya suatu objek.

Buatlah Sebuah Project Android Baru

Sebelum anda memulai membuat project, apa bila anda baru memulai membuat aplikasi android dan belum menginstal software yang diperlukan harap di instal terlebih dahulu.
 
 
Buatlah sebuah project dengan property :
Project name         : FormStuff
Built target             : Android 2.3
Aplication name     : formstuff
Package name       : com.wilis.formstuff
Activity                  : formstuff
Min SDK              : 9

1. Main.xml

ubah file main.xml menjadi seperti ini :

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:padding="10dp" />

<edittext
android:layout_width="match_parent"
android:id="@+id/edittext"
android:layout_height="wrap_content"/>

<checkbox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="check it out"
android:id="@+id/checkbox"/>


<radiogroup
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">

<radiobutton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio_red"
android:text="Red"/>

<radiobutton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/radio_blue"
android:text="Blue"/>
</RadioGroup>

<togglebutton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="Vibrate on"
android:textOff="Vibrate off"
android:id="@+id/togglebutton"/>

<ratingbar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingbar"
android:numStars="5"
android:stepSize="1.0"/>
</LinearLayout>

2. formstuff.java

Ubah file formstuff.java menjadi seperti ini :

package com.wilis.formstuff;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RatingBar;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.RatingBar.OnRatingBarChangeListener;

public class formstuff extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final RadioButton radio_red = (RadioButton)findViewById(R.id.radio_red);
final RadioButton radio_blue = (RadioButton)findViewById(R.id.radio_blue);
radio_red.setOnClickListener(radio_listener);
radio_blue.setOnClickListener(radio_listener);

final Button button=(Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v){
Toast.makeText(formstuff.this, "Brrrrr" ,Toast.LENGTH_SHORT).show();
}
});

final EditText edittext = (EditText)findViewById(R.id.edittext);
edittext.setOnKeyListener(new OnKeyListener(){
public boolean onKey(View v, int keyCode, KeyEvent event){
if((event.getAction()==KeyEvent.ACTION_DOWN)&&(keyCode == KeyEvent.KEYCODE_ENTER)){
Toast.makeText(formstuff.this, edittext.getText(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});

final CheckBox checkbox=(CheckBox)findViewById(R.id.checkbox);
checkbox.setOnClickListener(new OnClickListener(){
public void onClick(View v){
if(((CheckBox)v).isChecked()){
Toast.makeText(formstuff.this, "Selected", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(formstuff.this, "Not Selected", Toast.LENGTH_SHORT).show(); }
}
});

final ToggleButton togglebutton=(ToggleButton)findViewById(R.id.togglebutton);
togglebutton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
if(togglebutton.isChecked()){
Toast.makeText(formstuff.this, "Vibration On", Toast.LENGTH_SHORT );
}else{
Toast.makeText(formstuff.this, "Vibration Of", Toast.LENGTH_SHORT);
}
}
});

final RatingBar ratingbar=(RatingBar)findViewById(R.id.ratingbar);
ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener(){
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser){
Toast.makeText(formstuff.this, "New Rating : " + rating, Toast.LENGTH_SHORT).show();
}
});
}

private OnClickListener radio_listener = new OnClickListener(){
public void onClick(View v){
RadioButton rb=(RadioButton) v;
Toast.makeText(formstuff.this, rb.getText(), Toast.LENGTH_SHORT).show();
}
};

}
Sekarang coba anda jalankan aplikasi anda dengna cara tekan Ctrl + F11 pada keyboard. maka setiap action yang anda lakukan akan memunculkan sebuah message box toast.

Sumber :  Pemograman Aplikasi Mobile Smartphone dan tablet PC Berbasic Android Penerbit Informatika, Bandung, 2012 By : Nazruddin Safaat

Download Setup File from Downloader (100% Working Link)
Bagikan :
+
Previous
Next Post »

Artikel Terkait:

0 Komentar untuk "Membuat Aplikasi Android Ratingbar "

Silahkan berkomentar dengan bijak dan positif. Komentar anda menunjukkan sikap anda. Terima kasih :-)

 
Template By Kunci Dunia
Back To Top