Android Application Development Cookbook: 93 Recipes for Building Winning Apps



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

import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Figure 2-7 
www.it-ebooks.info


 
Recipe 2.4 using checkBoxes

51
//---CheckBox---
CheckBox checkBox = (CheckBox) findViewById(R.id.chkAutosave);
checkBox.setOnClickListener(new View.OnClickListener() 
{
public void onClick(View v) {
if (((CheckBox)v).isChecked()) 
Toast.makeText(getBaseContext(), 
"CheckBox is checked", 
Toast.LENGTH_LONG).show();
else
Toast.makeText(getBaseContext(), 
"CheckBox is unchecked", 
Toast.LENGTH_LONG).show();
}
});
}
}
To determine the state of a checkbox, you need to listen to its 
onClick
event. The 
isChecked()
method of the checkbox returns 
true
if the checkbox is checked, or 
false
if it is not. Figure 2-8 
shows the 
Toast
class displaying the state of the Autosave checkbox.
Figure 2-8 
www.it-ebooks.info


52

ChAPter 2
using Views to design the user interFAce
reCiPe 2.5 
iMPLeMenting A stAr rAting systeM
Android Versions
Level 1 and above
permissions
None
source code to download from Wrox.com
CheckBoxesRating.zip
The previous recipe introduced you to the checkbox, in particular the star checkbox. One popular 
use of the star checkbox is to implement a star rating system, whereby users tap on the stars to 
provide a rating for a particular item (such as user reviews for books, music, or venues). This recipe 
demonstrates how to implement this rating system.
solution
Assume you have the following code snippet in the 
activity_main.xml
file: 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/ratings" >
android:id="@+id/star1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="1" />
android:id="@+id/star2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="2" />
android:id="@+id/star3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="3" />
www.it-ebooks.info



Download 32,34 Mb.

Do'stlaringiz bilan baham:
1   ...   46   47   48   49   50   51   52   53   ...   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