SlideShare a Scribd company logo
1 of 4
Download to read offline
݇†ó£Œ´ÜŠO
«èê¡à¼õ£‚°
õ «î¬õò£ù ðô
衆«ó£™è¬÷ªè£‡
´œ÷¶.  ðò¡ð´ˆ
¶‹ SDK-‚° ãŸð 衆
«ó£™èÀ‹ ñ£Áð´‹.
ºî™ ꣡ø£è Rating
Bar ðò¡ð´ˆ¶õ¶ âš
õ£Á â¡ð¬îŠ 𣘊
«ð£‹.
ºîL™ ݇†
󣌴 ÜŠO«èê¡ à¼
õ£‚°õ â‚OŠC™
¹Fò Šó£ªü‚† å¡
P¬ù ªî£ìƒè «õ‡
´‹.
<?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" >
<TextView
android:id="@+id/lblRateMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rate"
android:textAppearance="?android:attr/textA
ppearanceMedium" />
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="4"
android:stepSize="1.0"
android:rating="2.0" />
<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/submit" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/lblResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/result"
android:textAppearance="?android:attr/textApp
earanceLarge" />
<TextView
android:id="@+id/txtRatingValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textApp
earanceSmall" />
</LinearLayout>
</LinearLayout>
Rating Bar Palette-™ àœ÷ ç𣘋
M†ªü†®™ (Form Widget) Þ¼‚°‹. (ðì‹-1)
ÜŠO«èêQ™ àœ÷ main.xml-™ ªì‚v†
MÎ, «ó†®ƒ 𣘠ð†ì¬ù ªè£‡´
F¬óJ¬ù à¼õ£‚è «õ‡´‹. main.xml
-‚è£ù Gó™ -1™ ªè£´‚èŠð†´œ÷¶.ðì‹-2
Gó™-1
ðì‹-3
ðì‹-1
«ó†®ƒ ð£˜
ðò¡ð´ˆ¶‹
º¬ø!
Ý¡†ó£Œ´ -2
Þ󣋰ñ£˜ ªô†²Iï£ó£òí¡
16
public class RatingbarActivity extends Activity
{
/** Called when the activity is first
created. */
private RatingBar ratingBar;
private TextView txtRatingValue;
private Button btnSubmit;
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnRatingBar();
addListenerOnButton();
}
public void addListenerOnRatingBar() {
ratingBar = (RatingBar)
findViewById(R.id.ratingBar);
txtRatingValue = (TextView)
findViewById(R.id.txtRatingValue);
//if rating value is changed,
//display the current rating value in the
result (textview) automatically
ratingBar.setOnRatingBarChangeListener(
new OnRatingBarChangeListener() {
public void
onRatingChanged(RatingBar ratingBar, float
rating,
boolean fromUser) {
txtRatingValue.setText(String.valueOf(ratin
g));
}
});
}
public void addListenerOnButton() {
ratingBar = (RatingBar)
findViewById(R.id.ratingBar);
btnSubmit = (Button)
findViewById(R.id.btnSubmit);
//if click on me, then display the current
rating value.
btnSubmit.setOnClickListener(new
OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(RatingbarActivity.this,
String.valueOf(ratingBar.getRating()),
Toast.LENGTH_SHORT).show();
}
});
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RatingBar;
import
android.widget.RatingBar.OnRatingBarChan
geListener;
import android.widget.TextView;
import android.widget.Toast;
Gó™-2
Gó™-3
Gó™-4
Gó™-5
ðì‹-4
ðì‹-5
Gó™ -1™ 𣘈b˜èœ
â¡ø£™ âˆî¬ù
«ó†®ƒ 𣘠«õ‡´‹
â¡ðî¬ù»‹ Step size
ñŸÁ‹ rating â¡ù â¡
ðî¬ù °PŠH†´œ
«÷£‹. main.xml-‚è£ù
F¬ó ðì‹-2™ àœ÷¶
«ð£¡Á‹ «î£¡Á‹.
Ü´ˆ¶ main.xml -‚è£ù
Ý‚®M†®J¬ù Rating
bar Activity.java âù ªðò
KìŠð†´œ÷¶.
ºîL™ ÜŠO«èê¡
«î¬õò£ù «ð‚«èx
è¬÷ Import ªêŒò
«õ‡´‹. (Gó™-2). Rating
bar Activity Class Activity
Class -ä Extend ªêŒ¶
package com.ram.ratingbar;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RatingBar;
import
android.widget.RatingBar.OnRatingBarChange
Listener;
import android.widget.TextView;
import android.widget.Toast;
public class RatingbarActivity extends Activity
{
/** Called when the activity is first created.
*/
private RatingBar ratingBar;
private TextView txtRatingValue;
private Button btnSubmit;
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnRatingBar();
addListenerOnButton();
}
public void addListenerOnRatingBar() {
ratingBar = (RatingBar)
findViewById(R.id.ratingBar);
txtRatingValue = (TextView)
findViewById(R.id.txtRatingValue);
//if rating value is changed,
//display the current rating value in the
result (textview) automatically
ratingBar.setOnRatingBarChangeListener(new
OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar
ratingBar, float rating,
boolean fromUser) {
txtRatingValue.setText(String.valueOf(rating));
}
});
}
public void addListenerOnButton() {
ratingBar = (RatingBar)
findViewById(R.id.ratingBar);
btnSubmit = (Button)
findViewById(R.id.btnSubmit);
//if click on me, then display the current
rating value.
btnSubmit.setOnClickListener(new
OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(RatingbarActivity.this,
String.valueOf(ratingBar.getRating()),
Toast.LENGTH_SHORT).show();
}
});
}
}
<?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" >
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Gó™-6
Gó™-7
ðì‹-6
ðò¡ð´ˆî «õ‡´‹. GóL™ ðò¡ð´ˆî
«ó†®ƒ 𣘂° ÝŠªü‚† ñ£PLò£è
«ó†®ƒ 𣘠â¡Á‹, ªì‚v† MÎMŸ°
ÝŠªü‚† ñ£PLò£è txtRating Value â¡Á‹,
ð†ìQŸ° (Button) ÝŠªü‚† ñ£PLò£è
btnsubmit Ýè ðò¡ð´ˆF àœ«÷£‹.
Oncrate ðò¡ð£†®™ SetContentView
Íô‹ main.xml -î¬ù
GóL™ Þ¬í‚A«ø£‹.
Ü´ˆ¶ addListerner
OnRating Bar() ñŸÁ‹
addListernerOnButton()
ðò¡ð´ˆîŠð†´œ÷¶.
«ó†®ƒ 𣘠AO‚ ªêŒ
»‹«ð£¶ â¡ù ï¬ì
ªðø «õ‡´‹ â¡ð
î¬ù addListernerOnRat
ingBar()-™ °PŠHì
«õ‡´‹. ð†ì¬ù
AO‚ ªêŒ»‹«ð£¶
â¡ù ï¬ìªðø «õ‡
´‹ â¡ðî¬ù
package ram.com.progressbar;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
public class ProgressbarActivity extends
Activity {
/** Called when the activity is first
created. */
// private static final int PROGRESS = 0x1;
private ProgressBar mProgress;
private int mProgressStatus = 0;
private Handler mHandler = new
Handler();
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mProgress = (ProgressBar)
findViewById(R.id.progressBar1);
// Start lengthy operation in a
background thread
new Thread(new Runnable() {
public void run() {
while (mProgressStatus < 100)
{
// mProgressStatus =
doWork();
// Update the progress bar
mHandler.post(new
Runnable() {
public void run() {
mProgress.setProgress(mProgressStatus);
}
});
}
}
}).start();
}
}
- ªî£ì¼‹
Gó™-8
ðì‹-7
addListernerOnButton() -™ °PŠHì «õ‡´‹.
(Gó™-3)
â‰î «ó†®ƒA¬ù AO‚ ªêŒA«ø£«ñ£,
ÜîŸè£ù ñFŠ¹ ªì‚v† MÎM™ «î£¡Á
õîŸè£è addListernerOnRatingBar()-‚è£ù
Gó™-4 ðò¡ð´Aø¶. Submit ð†ì¬ù AO‚
ªêŒî¾ì¡ â¡ù «ó†®ƒ àœ÷¶ â¡ð
î¬ù 裇H‚è addListernerOnButton() -‚è£ù
Gó™ ðò¡ð´Aø¶. F¬óJ™ 裇H‚è toast
ðò¡ð´ˆîŠð†´œ÷¶. (Gó™ -5)
«ó†®ƒ 𣘠݂®M†®‚è£ù Gó™ -6™
ªè£´‚èŠð†´œ÷¶. «ó†®ƒ 𣘠܊O
«èê¬ù ªêò™ð´ˆ¶õ RunRatingBar
â¡ø ð†ì¬ù â‚OŠC™ AO‚ ªêŒî£™
ªî£ìƒ°‹. (ðì‹-3)
ÜŠO«èê¡ ªêò™ðì ªî£ìƒAò¾ì¡
ðì‹-4™ àœ÷¶ «ð£¡Á F¬ó «î£¡Á‹.
Í¡ø£õ¶ Start (rating) J¬ù «î˜¾ ªêŒ
î¾ì¡ KꙆ®¡ ñFŠ¹ 3.0 â¡Á ñ£Á‹.
(ðì‹-5)
Submit -ä AO‚ ªêŒî¾ì¡ îèõ™
F¬óJ™ «î£¡Á‹. (ðì‹-6) Þ‰î ꣡Á
Íô‹ «ó†®ƒ 𣘠ðò¡ð´ˆ¶õ¶ âšõ£Á
â¡Á 𣘈«î£‹.
Ü´ˆî ꣡ø£è Progress Bar ðò¡ð´ˆ
¶õ¶ âšõ£Á â¡Á 𣘊«ð£‹. Progress
Bar -介 «ðô†®™ àœ÷ ç𣘋 M†
ªü†®L¼‰¶ «î˜‰ªî´‚èô£‹. Šó£Aóv
𣼂è£ù Gó™-7™ ªè£´‚èŠ ð†´œ÷¶.
Þƒ° Linear Layout ðò¡ð´ˆF Šó£Aóv
𣘠ðò¡ð´ˆîŠð†´œ÷¶. main.xml -è£ù
Activity -Progressbar Activity Ý°‹. Šó£Aóv
𣘠݂®M†®JÂœ thread å¡P¬ù à¼
õ£‚è «õ‡´‹.
Gó™-8-™ Ý‚®M†®J™ ðò¡ð´ˆîŠ
ð´‹ Gó™ ªè£´‚èŠð†´œ÷¶. ÜŠO
«èê¡ ªêò™ð†ì¾ì¡ ðì‹-7-™ àœ÷¶
«ð£¡Á Šó£Aóv 𣘠F¬óJ™ «î£¡Á‹.

More Related Content

What's hot

「レガシーコード」とはいったい?
「レガシーコード」とはいったい?「レガシーコード」とはいったい?
「レガシーコード」とはいったい?Hiroyuki Ohnaka
 
Sentinel Hardware Keys
Sentinel Hardware KeysSentinel Hardware Keys
Sentinel Hardware KeysJong-hyeok Kim
 
八月星观察-互联网创业月刊
八月星观察-互联网创业月刊八月星观察-互联网创业月刊
八月星观察-互联网创业月刊MOBINODE
 
Readme ko
Readme koReadme ko
Readme koThata22
 
241 Ch
241 Ch241 Ch
241 Chanjaan
 
Code Template with EA
Code Template with EACode Template with EA
Code Template with EAYoungSu Son
 
Apport de la simulation sur maquette adaptative à la démarche de conception d...
Apport de la simulation sur maquette adaptative à la démarche de conception d...Apport de la simulation sur maquette adaptative à la démarche de conception d...
Apport de la simulation sur maquette adaptative à la démarche de conception d...Benoit LANGARD - PhD
 
211 Ch
211 Ch211 Ch
211 Chanjaan
 
Web技術勉強会 第28回
Web技術勉強会 第28回Web技術勉強会 第28回
Web技術勉強会 第28回龍一 田中
 
Написание DSL в Perl
Написание DSL в PerlНаписание DSL в Perl
Написание DSL в Perlmayperl
 

What's hot (20)

jQuery
jQueryjQuery
jQuery
 
Sample Add Application uisng Android (in tamil)
Sample Add Application uisng Android (in tamil)Sample Add Application uisng Android (in tamil)
Sample Add Application uisng Android (in tamil)
 
「レガシーコード」とはいったい?
「レガシーコード」とはいったい?「レガシーコード」とはいったい?
「レガシーコード」とはいったい?
 
Intro. to JavaScript
Intro. to JavaScriptIntro. to JavaScript
Intro. to JavaScript
 
Sentinel Hardware Keys
Sentinel Hardware KeysSentinel Hardware Keys
Sentinel Hardware Keys
 
Installing Eclipse (in tamil)
Installing Eclipse (in tamil)Installing Eclipse (in tamil)
Installing Eclipse (in tamil)
 
Shared Preference in Android App
Shared Preference in Android AppShared Preference in Android App
Shared Preference in Android App
 
八月星观察-互联网创业月刊
八月星观察-互联网创业月刊八月星观察-互联网创业月刊
八月星观察-互联网创业月刊
 
jQuery Tutorial
jQuery TutorialjQuery Tutorial
jQuery Tutorial
 
Readme ko
Readme koReadme ko
Readme ko
 
241 Ch
241 Ch241 Ch
241 Ch
 
Code Template with EA
Code Template with EACode Template with EA
Code Template with EA
 
Apport de la simulation sur maquette adaptative à la démarche de conception d...
Apport de la simulation sur maquette adaptative à la démarche de conception d...Apport de la simulation sur maquette adaptative à la démarche de conception d...
Apport de la simulation sur maquette adaptative à la démarche de conception d...
 
b2con2006_sato
b2con2006_satob2con2006_sato
b2con2006_sato
 
211 Ch
211 Ch211 Ch
211 Ch
 
Web技術勉強会 第28回
Web技術勉強会 第28回Web技術勉強会 第28回
Web技術勉強会 第28回
 
Написание DSL в Perl
Написание DSL в PerlНаписание DSL в Perl
Написание DSL в Perl
 
Capitulo 27 - Corriente y Resistencia
Capitulo 27 - Corriente y ResistenciaCapitulo 27 - Corriente y Resistencia
Capitulo 27 - Corriente y Resistencia
 
Capitulo 28 - Circuitos Corriente Directa
Capitulo 28 - Circuitos Corriente DirectaCapitulo 28 - Circuitos Corriente Directa
Capitulo 28 - Circuitos Corriente Directa
 
Bhale chance
Bhale chanceBhale chance
Bhale chance
 

More from Dr. Ramkumar Lakshminarayanan

Using many languages in single Android App (in tamil)
Using many languages in single Android App (in tamil)Using many languages in single Android App (in tamil)
Using many languages in single Android App (in tamil)Dr. Ramkumar Lakshminarayanan
 

More from Dr. Ramkumar Lakshminarayanan (19)

IT security awareness
IT security awarenessIT security awareness
IT security awareness
 
Basics of IT security
Basics of IT securityBasics of IT security
Basics of IT security
 
IT Security Awareness Posters
IT Security Awareness PostersIT Security Awareness Posters
IT Security Awareness Posters
 
Normalisation revision
Normalisation revisionNormalisation revision
Normalisation revision
 
Windows mobile programming
Windows mobile programmingWindows mobile programming
Windows mobile programming
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Web technology today
Web technology todayWeb technology today
Web technology today
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Phonegap for Android
Phonegap for AndroidPhonegap for Android
Phonegap for Android
 
Create and Sell Android App (in tamil)
Create and Sell Android App (in tamil)Create and Sell Android App (in tamil)
Create and Sell Android App (in tamil)
 
Android Tips (Tamil)
Android Tips (Tamil)Android Tips (Tamil)
Android Tips (Tamil)
 
Android Animation (in tamil)
Android Animation (in tamil)Android Animation (in tamil)
Android Animation (in tamil)
 
Single Touch event view in Android (in tamil)
Single Touch event view in Android (in tamil)Single Touch event view in Android (in tamil)
Single Touch event view in Android (in tamil)
 
Android Application using seekbar (in tamil)
Android Application using seekbar (in tamil)Android Application using seekbar (in tamil)
Android Application using seekbar (in tamil)
 
GPS in Android (in tamil)
GPS in Android (in tamil)GPS in Android (in tamil)
GPS in Android (in tamil)
 
Using many languages in single Android App (in tamil)
Using many languages in single Android App (in tamil)Using many languages in single Android App (in tamil)
Using many languages in single Android App (in tamil)
 
Data Storage in Android App
Data Storage in Android AppData Storage in Android App
Data Storage in Android App
 
Part 7
Part 7Part 7
Part 7
 
Layout Object in Android App
Layout Object in Android AppLayout Object in Android App
Layout Object in Android App
 

Rating Bar in Android Example

  • 1. ݇†ó£Œ´ÜŠO «èê¡à¼õ£‚° õ «î¬õò£ù ðô 衆«ó£™è¬÷ªè£‡ ´œ÷¶.  ðò¡ð´ˆ ¶‹ SDK-‚° ãŸð 衆 «ó£™èÀ‹ ñ£Áð´‹. ºî™ ꣡ø£è Rating Bar ðò¡ð´ˆ¶õ¶ âš õ£Á â¡ð¬îŠ 𣘊 «ð£‹. ºîL™ ݇† 󣌴 ÜŠO«èê¡ à¼ õ£‚°õ â‚OŠC™ ¹Fò Šó£ªü‚† å¡ P¬ù ªî£ìƒè «õ‡ ´‹. <?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" > <TextView android:id="@+id/lblRateMe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/rate" android:textAppearance="?android:attr/textA ppearanceMedium" /> <RatingBar android:id="@+id/ratingBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numStars="4" android:stepSize="1.0" android:rating="2.0" /> <Button android:id="@+id/btnSubmit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/submit" /> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/lblResult" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/result" android:textAppearance="?android:attr/textApp earanceLarge" /> <TextView android:id="@+id/txtRatingValue" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textAppearance="?android:attr/textApp earanceSmall" /> </LinearLayout> </LinearLayout> Rating Bar Palette-™ àœ÷ ç𣘋 M†ªü†®™ (Form Widget) Þ¼‚°‹. (ðì‹-1) ÜŠO«èêQ™ àœ÷ main.xml-™ ªì‚v† MÎ, «ó†®ƒ 𣘠ð†ì¬ù ªè£‡´ F¬óJ¬ù à¼õ£‚è «õ‡´‹. main.xml -‚è£ù Gó™ -1™ ªè£´‚èŠð†´œ÷¶.ðì‹-2 Gó™-1 ðì‹-3 ðì‹-1 «ó†®ƒ 𣘠ðò¡ð´ˆ¶‹ º¬ø!
  • 2. Ý¡†ó£Œ´ -2 Þ󣋰ñ£˜ ªô†²Iï£ó£òí¡ 16 public class RatingbarActivity extends Activity { /** Called when the activity is first created. */ private RatingBar ratingBar; private TextView txtRatingValue; private Button btnSubmit; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); addListenerOnRatingBar(); addListenerOnButton(); } public void addListenerOnRatingBar() { ratingBar = (RatingBar) findViewById(R.id.ratingBar); txtRatingValue = (TextView) findViewById(R.id.txtRatingValue); //if rating value is changed, //display the current rating value in the result (textview) automatically ratingBar.setOnRatingBarChangeListener( new OnRatingBarChangeListener() { public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { txtRatingValue.setText(String.valueOf(ratin g)); } }); } public void addListenerOnButton() { ratingBar = (RatingBar) findViewById(R.id.ratingBar); btnSubmit = (Button) findViewById(R.id.btnSubmit); //if click on me, then display the current rating value. btnSubmit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(RatingbarActivity.this, String.valueOf(ratingBar.getRating()), Toast.LENGTH_SHORT).show(); } }); import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.RatingBar; import android.widget.RatingBar.OnRatingBarChan geListener; import android.widget.TextView; import android.widget.Toast; Gó™-2 Gó™-3 Gó™-4 Gó™-5 ðì‹-4 ðì‹-5 Gó™ -1™ 𣘈b˜èœ â¡ø£™ âˆî¬ù «ó†®ƒ 𣘠«õ‡´‹ â¡ðî¬ù»‹ Step size ñŸÁ‹ rating â¡ù â¡ ðî¬ù °PŠH†´œ «÷£‹. main.xml-‚è£ù F¬ó ðì‹-2™ àœ÷¶ «ð£¡Á‹ «î£¡Á‹. Ü´ˆ¶ main.xml -‚è£ù Ý‚®M†®J¬ù Rating bar Activity.java âù ªðò KìŠð†´œ÷¶. ºîL™ ÜŠO«èê¡ «î¬õò£ù «ð‚«èx è¬÷ Import ªêŒò «õ‡´‹. (Gó™-2). Rating bar Activity Class Activity Class -ä Extend ªêŒ¶
  • 3. package com.ram.ratingbar; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.RatingBar; import android.widget.RatingBar.OnRatingBarChange Listener; import android.widget.TextView; import android.widget.Toast; public class RatingbarActivity extends Activity { /** Called when the activity is first created. */ private RatingBar ratingBar; private TextView txtRatingValue; private Button btnSubmit; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); addListenerOnRatingBar(); addListenerOnButton(); } public void addListenerOnRatingBar() { ratingBar = (RatingBar) findViewById(R.id.ratingBar); txtRatingValue = (TextView) findViewById(R.id.txtRatingValue); //if rating value is changed, //display the current rating value in the result (textview) automatically ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { txtRatingValue.setText(String.valueOf(rating)); } }); } public void addListenerOnButton() { ratingBar = (RatingBar) findViewById(R.id.ratingBar); btnSubmit = (Button) findViewById(R.id.btnSubmit); //if click on me, then display the current rating value. btnSubmit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(RatingbarActivity.this, String.valueOf(ratingBar.getRating()), Toast.LENGTH_SHORT).show(); } }); } } <?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" > <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> Gó™-6 Gó™-7 ðì‹-6 ðò¡ð´ˆî «õ‡´‹. GóL™ ðò¡ð´ˆî «ó†®ƒ 𣘂° ÝŠªü‚† ñ£PLò£è «ó†®ƒ 𣘠â¡Á‹, ªì‚v† MÎMŸ° ÝŠªü‚† ñ£PLò£è txtRating Value â¡Á‹, ð†ìQŸ° (Button) ÝŠªü‚† ñ£PLò£è btnsubmit Ýè ðò¡ð´ˆF àœ«÷£‹. Oncrate ðò¡ð£†®™ SetContentView Íô‹ main.xml -î¬ù GóL™ Þ¬í‚A«ø£‹. Ü´ˆ¶ addListerner OnRating Bar() ñŸÁ‹ addListernerOnButton() ðò¡ð´ˆîŠð†´œ÷¶. «ó†®ƒ 𣘠AO‚ ªêŒ »‹«ð£¶ â¡ù ï¬ì ªðø «õ‡´‹ â¡ð î¬ù addListernerOnRat ingBar()-™ °PŠHì «õ‡´‹. ð†ì¬ù AO‚ ªêŒ»‹«ð£¶ â¡ù ï¬ìªðø «õ‡ ´‹ â¡ðî¬ù
  • 4. package ram.com.progressbar; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.widget.ProgressBar; public class ProgressbarActivity extends Activity { /** Called when the activity is first created. */ // private static final int PROGRESS = 0x1; private ProgressBar mProgress; private int mProgressStatus = 0; private Handler mHandler = new Handler(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mProgress = (ProgressBar) findViewById(R.id.progressBar1); // Start lengthy operation in a background thread new Thread(new Runnable() { public void run() { while (mProgressStatus < 100) { // mProgressStatus = doWork(); // Update the progress bar mHandler.post(new Runnable() { public void run() { mProgress.setProgress(mProgressStatus); } }); } } }).start(); } } - ªî£ì¼‹ Gó™-8 ðì‹-7 addListernerOnButton() -™ °PŠHì «õ‡´‹. (Gó™-3) â‰î «ó†®ƒA¬ù AO‚ ªêŒA«ø£«ñ£, ÜîŸè£ù ñFŠ¹ ªì‚v† MÎM™ «î£¡Á õîŸè£è addListernerOnRatingBar()-‚è£ù Gó™-4 ðò¡ð´Aø¶. Submit ð†ì¬ù AO‚ ªêŒî¾ì¡ â¡ù «ó†®ƒ àœ÷¶ â¡ð î¬ù 裇H‚è addListernerOnButton() -‚è£ù Gó™ ðò¡ð´Aø¶. F¬óJ™ 裇H‚è toast ðò¡ð´ˆîŠð†´œ÷¶. (Gó™ -5) «ó†®ƒ 𣘠݂®M†®‚è£ù Gó™ -6™ ªè£´‚èŠð†´œ÷¶. «ó†®ƒ 𣘠܊O «èê¬ù ªêò™ð´ˆ¶õ RunRatingBar â¡ø ð†ì¬ù â‚OŠC™ AO‚ ªêŒî£™ ªî£ìƒ°‹. (ðì‹-3) ÜŠO«èê¡ ªêò™ðì ªî£ìƒAò¾ì¡ ðì‹-4™ àœ÷¶ «ð£¡Á F¬ó «î£¡Á‹. Í¡ø£õ¶ Start (rating) J¬ù «î˜¾ ªêŒ î¾ì¡ KꙆ®¡ ñFŠ¹ 3.0 â¡Á ñ£Á‹. (ðì‹-5) Submit -ä AO‚ ªêŒî¾ì¡ îèõ™ F¬óJ™ «î£¡Á‹. (ðì‹-6) Þ‰î ꣡Á Íô‹ «ó†®ƒ 𣘠ðò¡ð´ˆ¶õ¶ âšõ£Á â¡Á 𣘈«î£‹. Ü´ˆî ꣡ø£è Progress Bar ðò¡ð´ˆ ¶õ¶ âšõ£Á â¡Á 𣘊«ð£‹. Progress Bar -介 «ðô†®™ àœ÷ ç𣘋 M† ªü†®L¼‰¶ «î˜‰ªî´‚èô£‹. Šó£Aóv 𣼂è£ù Gó™-7™ ªè£´‚èŠ ð†´œ÷¶. Þƒ° Linear Layout ðò¡ð´ˆF Šó£Aóv 𣘠ðò¡ð´ˆîŠð†´œ÷¶. main.xml -è£ù Activity -Progressbar Activity Ý°‹. Šó£Aóv 𣘠݂®M†®JÂœ thread å¡P¬ù ༠õ£‚è «õ‡´‹. Gó™-8-™ Ý‚®M†®J™ ðò¡ð´ˆîŠ ð´‹ Gó™ ªè£´‚èŠð†´œ÷¶. ÜŠO «èê¡ ªêò™ð†ì¾ì¡ ðì‹-7-™ àœ÷¶ «ð£¡Á Šó£Aóv 𣘠F¬óJ™ «î£¡Á‹.