Android AlertDialog操作代码详解

移动开发 Android
Android AlertDialog的使用方法对于初学者来说是比较容易理解的。通过下面这段代码示例就应该可以充分的掌握其中技巧。

对于刚刚接触Android这一手机操作系统的朋友来说,可能还对其中一些重要的功能不是很清楚,以及具体应用技巧掌握不牢。在这里我们就来通过一段代码的解读,为大家详细介绍Android AlertDialog的使用方法。

Android AlertDialog代码示例:

package maximyudin.AlertDialogBuilderSample;   
import android.app.Activity;   
import android.os.Bundle;   
import android.widget.Button;   
import android.view.View;   
import android.app.AlertDialog;   
import android.content.DialogInterface;   
public class AlertDialogBuilderSample extends Activity {   
@Override   
public void onCreate(Bundle icicle) {   
super.onCreate(icicle);   
setContentView(R.layout.main);   
final Button btnQuit = (Button) findViewById(R.id.btnQuit);   
btnQuit.setOnClickListener(new Button.OnClickListener() {   
public void onClick(View v) {   
new AlertDialog.Builder(AlertDialogBuilderSample.this)   
.setTitle(“Question”)   
.setMessage(“Are you sure that you want to quit?”)   
.setIcon(R.drawable.question)   
.setPositiveButton(“Yes”, new DialogInterface.OnClickListener() {   
public void onClick(DialogInterface dialog, int whichButton) {   
setResult(RESULT_OK);   
finish();   
}   
})   
.setNegativeButton(“No”, new DialogInterface.OnClickListener() 
{   
public void onClick(DialogInterface dialog, int whichButton) 
{   
}   
})   
.show();   
}   
});   
final Button btnTravels = (Button) findViewById(R.id.btnTravels);   
btnTravels.setOnClickListener(new Button.OnClickListener() 
{   
public void onClick(View v) {   
new AlertDialog.Builder(AlertDialogBuilderSample.this)   
.setTitle(“I want to go to”)   
.setItems(R.array.items_indide_dialog,   
new DialogInterface.OnClickListener() {   
public void onClick(DialogInterface dialog, int whichcountry) 
{   
String[] travelcountries =   
getResources().getStringArray(R.array.items_indide_dialog);   
new AlertDialog.Builder(AlertDialogBuilderSample.this)   
.setMessage(“I’m going to “ + travelcountries[whichcountry])   
.setNeutralButton(“Cancel”,   
new DialogInterface.OnClickListener() {   
public void onClick(DialogInterface dialog, int whichButton)   
{   
}   
})   
.show();   
}   
})   
.show();   
}   
});   
}   

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.

Android AlertDialog具体使用方法就为大家介绍到这里。

【编辑推荐】

  1. Android监听通话正确操作方法介绍
  2. Android震动代码解读
  3. Android移植实际应用要点解析
  4. Android启动Java程序应用方法详解
  5. Android使用Animation技巧讲解
责任编辑:曹凯 来源: javaeye.com
相关推荐

2010-02-04 10:58:29

Android 源代码

2011-05-04 09:48:14

2010-03-17 15:01:24

Python复制文件

2009-09-18 14:51:19

LINQ TO SQL

2021-06-18 06:31:55

PyTorchPython深度学习

2010-03-17 16:27:39

Python矩阵转置

2010-08-30 19:55:27

配置DHCP

2011-07-04 17:18:23

Qt SQLite 数据库

2014-07-28 10:09:30

Android

2013-11-14 10:42:48

MTPAndroid

2011-05-27 15:02:15

Android ListView

2014-07-24 09:11:34

2017-01-11 19:05:45

AndroidAndroid Loa详解

2013-11-14 16:50:08

2022-12-02 09:02:36

Swift代码异步

2010-01-18 16:17:53

C++代码

2009-08-20 11:01:51

C#操作内存

2021-08-12 14:49:44

操作系统线程进程

2009-08-31 09:23:05

2009-07-17 17:11:47

Ruby生成JVM代码
点赞
收藏

51CTO技术栈公众号