package com.powenko.TutorialDialogCumtomerWithButton; import android.app.Activity; import android.os.Bundle; import android.view.View.OnClickListener; import android.view.View; import android.widget.Button; import android.widget.Toast; import android.app.AlertDialog; import android.content.DialogInterface; import android.app.ProgressDialog; public class TutorialDialogCumtomerWithButton extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // set a click listener on the toast button Button toast = (Button) findViewById(R.id.toastbtn); toast.setOnClickListener(this); // set a click listener on the alert button Button alert = (Button) findViewById(R.id.alertbtn); alert.setOnClickListener(this); // set a click listener on the yesno button Button yesno = (Button) findViewById(R.id.yesnobtn); yesno.setOnClickListener(this); // set a click listener on the progress button Button progress = (Button) findViewById(R.id.progressbtn); progress.setOnClickListener(this); } public void onClick(View view) { // which button is clicked? // the Toast button if (view == findViewById(R.id.toastbtn)) { // display the toast popup window Toast.makeText(this, "This is the Toast message", Toast.LENGTH_LONG).show(); } // the Alert button the activated if (view == findViewById(R.id.alertbtn)) { // prepare the alert box AlertDialog.Builder alertbox = new AlertDialog.Builder(this); // set the message to display alertbox.setMessage("This is the alertbox!"); // add a neutral button to the alert box and assign a click listener alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() { // click listener on the alert box public void onClick(DialogInterface arg0, int arg1) { // the button was clicked Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show(); } }); // show it alertbox.show(); } // the yesno button is clicked if (view == findViewById(R.id.yesnobtn)) { // prepare the alert box AlertDialog.Builder alertbox = new AlertDialog.Builder(this); // set the message to display alertbox.setMessage("This is the alertbox!"); // set a positive/yes button and create a listener alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface arg0, int arg1) { Toast.makeText(getApplicationContext(), "'Yes' button clicked", Toast.LENGTH_SHORT).show(); } }); // set a negative/no button and create a listener alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface arg0, int arg1) { Toast.makeText(getApplicationContext(), "'No' button clicked", Toast.LENGTH_SHORT).show(); } }); // display box alertbox.show(); } // progress button clicked if (view == findViewById(R.id.progressbtn)) { // prepare the dialog box ProgressDialog dialog = new ProgressDialog(this); // make the progress bar cancelable dialog.setCancelable(true); // set a message text dialog.setMessage("Loading..."); // show it dialog.show(); } } }
CH01 簡介篇
- 02 Android Tutorial, Begin android 4.0.x..
- 受保護的內容: android app, best anti-virus app..
- Android M 新版本 2015 第三季正式釋出..
- Android 讀者專區
- Google Apps Marketplace
- PowenKo,Android Tutorial 004,Begin , An..
- 對於完全不了解app 的幾個常見問答,和建議的書籍..
- android 語言, 教學文件 021-1-1, UI, 使用設計 Title..
- android, ui, dialog
- Android, ui, Listview, 修掉 選取時背景變成黑色的問題..
- android, ui, tab
- Android,UI 在程式中即時加上其他的UI..
- android,ui,Working with the Android Cale..
- android-ProgressDialog 不能在 TabActivity 執..
- hide keyboard
- ui, thread, Using threads and ProgressDi..