Android Application Development Cookbook: 93 Recipes for Building Winning Apps


Recipe 2.5 implementing a star Rating system



Download 32,34 Mb.
Pdf ko'rish
bet51/56
Sana26.02.2022
Hajmi32,34 Mb.
#470540
1   ...   48   49   50   51   52   53   54   55   56
Bog'liq
Android Application Development Cookbook

 
Recipe 2.5 implementing a star Rating system

53
android:id="@+id/star4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="4" />
android:id="@+id/star5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="5" />

Note that the checkboxes are arranged horizontally and displayed using the star style. Also note that 
each checkbox is tagged using the 
android:tag
attribute. This will be useful later when you need to 
programmatically locate the individual checkbox. 
The following code snippet shows how to implement the star rating system:
package net.learn2develop.checkboxesratings;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
LinearLayout rating;
CheckBox star;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//---get the layout containing the stars---
rating = (LinearLayout) findViewById(R.id.ratings);
for (int i = 1; i <= 5; i++) {
star = (CheckBox) rating.findViewWithTag(String.valueOf(i));
star.setOnClickListener(starsListener);
}
}
private OnClickListener starsListener = new OnClickListener() {
public void onClick(View view) {
//---get the tag of the star selected---
int tag = Integer.valueOf((String) view.getTag());
//---check all the stars up to the one touched---
www.it-ebooks.info



Download 32,34 Mb.

Do'stlaringiz bilan baham:
1   ...   48   49   50   51   52   53   54   55   56




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish