用户输入一个地址,当查询位置失败时,弹出对话框

package com.example.androidtest;import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.util.Log;public class MainActivity extends Activity {public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);final AlertDialog.Builder adb = new AlertDialog.Builder(this);final EditText addressfield = (EditText)findViewById(R.id.address);final Button button = (Button)findViewById(R.id.launchmap);button.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {try {String address = addressfield.getText().toString();address = address.replace(' ', '+');Intent geoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + address));startActivity(geoIntent);} catch (Exception e) {AlertDialog ad = adb.create();ad.setMessage("Failed to launch");ad.show();}}});}
}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">
<TextView  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Please enter your home address."/>
<EditTextandroid:id="@+id/address"android:layout_width="fill_parent" android:layout_height="wrap_content" android:autoText="true"/>
<Buttonandroid:id="@+id/launchmap"android:layout_width="wrap_content" android:layout_height="wrap_content"android:text="Show Map"/>
<TextView  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Unlocking Android"/>
</LinearLayout>

Dialog的使用(一):用AlertDialog提示相关推荐

  1. android漂亮的dialog,一个好看的Android AlertDialog

    最近项目需求,需要一个好看一点的提示框,网上搜罗一番,发现sweetDialog 人气很高,但是到了实际使用的时候,发现有些问题不太好解决,而且已经三年没有更新了,而其他的库,更是达不到要求.所以索性 ...

  2. Dialog的使用(二):AlertDialog.setItems

    通过AlertDialog.Builder的setItems方法可以创建简单的列表对话框. package com.example.androidtest;import android.os.Bund ...

  3. android dialog 自定义布局,如何设置AlertDialog的自定义布局?

    调用我的对话框:alertDialog = showInfoDialog(message = "$wrongPasscodeMessage\n$retryMessage") 方法如 ...

  4. Flutter 入门指北(Part 9)之弹窗和提示(SnackBar、BottomSheet、Dialog)

    该文已授权公众号 「码个蛋」,转载请指明出处 前面的小节把常用的一些部件都介绍了,这节介绍下 Flutter 中的一些操作提示.Flutter 中的操作提示主要有这么几种 SnackBar.Botto ...

  5. 安卓自定义控件之设计自己的提示dialog

    当需要设计自己的对话框dialog,并且按照自己要求定制,比如最常见的,操作提示,操作成功显示成功的信息,失败时也显示对应的提示 先看看效果: 步骤: 1.继承Dialog类,定义几个变量 priva ...

  6. Dialog外部点击事件

    Dialog对话框,点击对话框外部不会关闭对话框. dialog.setCancelable(true)//关闭 dialog.setCancelable(false)//不关闭AlertDialog ...

  7. 信息提醒之对话框(AlertDialog + ProgressDialog)-更新中

    概念 Android中的对话框需要使用AlertDialog类来显示,主要用于显示提醒信息,不过这个对话框类可不仅仅能用来显示一些信息,我们可以在对话框中防止任何的控件,使其成为一个复杂且功能强大的用 ...

  8. 【Android】Android 8种对话框(Dialog)

    1.写在前面 Android提供了丰富的Dialog函数,本文介绍最常用的8种对话框的使用方法,包括普通(包含提示消息和按钮).列表.单选.多选.等待.进度条.编辑.自定义等多种形式,将在第2部分介绍 ...

  9. android+自定义alertdialog,安卓自定义AlertDialog

    AlertDialog.png 使用方法 example: DialogUtil.showAlertDialog(getActivity(), R.mipmap.restart, "退出提示 ...

最新文章

  1. 两个数组的交集 II
  2. 5 种将死的编程语言!
  3. 展望:模型驱动的深度学习
  4. Ubuntu 之 atom 安装以及 常用配置
  5. 二分匹配(匈牙利算法)
  6. JUnit与TestNG:您应该选择哪种测试框架?
  7. jq上传file到php,jQuery文件上传
  8. C两个小例子(数组与指针)
  9. win10 .net framework 3.5 安装报错 0x800F0954问题
  10. Ubuntu 查看磁盘挂载和磁盘剩余容量
  11. 用《内网穿山甲》共享内网中的远程桌面服务
  12. L3G4200D + ADXL345 卡尔曼滤波
  13. ps安装失败的快速解决方法
  14. PPT - 双屏幕情况下,如何设置 PPT 不在主屏幕显示问题?
  15. 深入理解Flash的沙箱 – Application Domains
  16. 前端 关于汇率的计算
  17. 使用RabbitMQ出现Plugin configuration unchanged.问题
  18. 惠头条全行业开户竞价推广投放怎么避免无效点击
  19. JavaScript : 对LHS和RHS两个名词的理解
  20. Mate 50,来了!

热门文章

  1. 增强.net开发的5个非常有用的Visual Studio 2012扩展
  2. python使用input函数时、必须添加提示文字-Python基础教程(4)使用input函数实现用户交互...
  3. python使用教程pandas-十分钟搞定pandas(入门教程)
  4. python表白对话框-python tkinter-消息框、对话框、文件对话框
  5. python表白对话框-python会话框
  6. python编程从入门到精通 叶维忠 pdf-叶维忠《Python编程从入门到精通》PDF
  7. python下载安装教程mac-Anaconda2 Mac版下载
  8. python版本越高越好吗-5个Python特性 越早知道越好的
  9. python编写一个软件-软件代做:利用Python编写一个行业专用的小计算器
  10. python语言怎么输入-python如何用input输入数组