Android Application Development Cookbook: 93 Recipes for Building Winning Apps


android:layout_width="wrap_content"



Download 32,34 Mb.
Pdf ko'rish
bet43/56
Sana26.02.2022
Hajmi32,34 Mb.
#470540
1   ...   39   40   41   42   43   44   45   46   ...   56
Bog'liq
Android Application Development Cookbook

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:onClick="onToggle" />

The most common way to handle a Button event is to implement its 
onClick
event. There are a few 
ways to do this:
package net.learn2develop.buttons;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import android.widget.ToggleButton;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//---Button view---
Button btn = (Button) findViewById(R.id.button3); 
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Toast.makeText(getBaseContext(), "Button 3 was clicked!", 
Toast.LENGTH_SHORT).show();
}
});
//---the two buttons are wired to the same event handler--- 
Button btn4 = (Button) findViewById(R.id.button4);
btn4.setOnClickListener(btnListener);
Button btn5 = (Button) findViewById(R.id.button5); 
btn5.setOnClickListener(btnListener);
}
//---create an anonymous class to act as a button click listener---
private OnClickListener btnListener = new OnClickListener() {
www.it-ebooks.info


42

ChAPter 2
using Views to design the user interFAce
public void onClick(View view)
{
Toast.makeText(getBaseContext(),

Download 32,34 Mb.

Do'stlaringiz bilan baham:
1   ...   39   40   41   42   43   44   45   46   ...   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