android基础篇:提示框AlertDialog实例
来源:互联网 发布:大数据与生活的联系 编辑:程序博客网 时间:2024/06/03 22:00
string.xml
<?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">TestBase</string> <string name="city_name">城市</string> <string name="city_default">北京</string> <string name="btn_yesorno">是否选择提示框</string> <string name="btn_listitem">列表选择提示框</string></resources>
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.mytest.testbase.MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/city_name" /> <EditText android:id="@+id/city_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="@string/city_default" android:inputType="text" /> <Button android:id="@+id/btn_yesorno" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="YesOrNoOnClick" android:text="@string/btn_yesorno" /> <Button android:id="@+id/btn_listitem" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="ListItemOnClick" android:text="@string/btn_listitem" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tv_result" /> </LinearLayout>
MainActivity.java
package com.mytest.testbase;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.content.DialogInterface;import android.os.Bundle;import android.view.View;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends Activity {private TextView textview_result;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);textview_result = (TextView) this.findViewById(R.id.tv_result);}/** * 是否选择提示框 * * @param view */public void YesOrNoOnClick(View view) {Builder builder = new AlertDialog.Builder(this);builder.setMessage("确认删除吗?").setPositiveButton("是", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// Toast.makeText(getApplicationContext(), "删除成功",// Toast.LENGTH_SHORT).show();textview_result.setText("删除成功");}}).setNegativeButton("否", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// Toast.makeText(getApplicationContext(), "删除失败",// Toast.LENGTH_SHORT).show();textview_result.setText("删除失败");}});AlertDialog dialog = builder.create();dialog.show();}/** * 列表项选择提示框 * * @param view */public void ListItemOnClick(View view) {Builder builder = new AlertDialog.Builder(this);final String[] cities = { "广州", "上海", "北京", "香港", "澳门" };builder.setTitle("选择城市").setItems(cities, new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {textview_result.setText("选择的城市是" + cities[which]);}});AlertDialog dialog = builder.create();dialog.show();}}
0 0
- android基础篇:提示框AlertDialog实例
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用设置AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android控件之AlertDialog-信息提示框
- android基础学习(6)-------AlertDialog.Builder提示对话框
- An internal error occurred during: "Retrieving archetypes:".
- nim和面型对象(四)
- html img Src base64 图片显示
- 利用spring获取ip地址
- android开发之调试技巧
- android基础篇:提示框AlertDialog实例
- linux下软链接和硬链接的区别
- shell脚本-添加用户(非交互式)
- C++中修改由const修饰的私有属性
- CSU 1639队长,我想进集训队!
- OC学习之C语言递归方式实现10进制转R(2-16)进制
- day04--面向对象--内部类
- CSU 1640机智的刷题方式
- Lua_绑定tinyxml到Lua中解析XML