Android Application Development Cookbook: 93 Recipes for Building Winning Apps


Figure 2-5  www.it-ebooks.info 48



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

Figure 2-5 
www.it-ebooks.info


48

ChAPter 2
using Views to design the user interFAce
The following code snippet shows how to determine whether a radio button is checked:
package net.learn2develop.radiobuttons;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//---RadioButton---
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.rdbGp1);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton rb1 = (RadioButton) findViewById(R.id.rdb1);
if (rb1.isChecked()) {
Toast.makeText(getBaseContext(), 
"Option 1 checked!", 
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getBaseContext(), 
"Option 2 checked!", 
Toast.LENGTH_LONG).show();
}
}
});
}
}
You can determine whether a radio button is checked by listening to the 
onCheckedChanged
event 
on of the 
RadioGroup
element. This event is fired whenever a radio button contained within it is 
checked or unchecked. To determine the state of a radio button, examine its 
isChecked()
method. 
Figure 2-6 shows the 
Toast
class displaying a message when a radio button is clicked on the 
emulator. 
www.it-ebooks.info



Download 32,34 Mb.

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