android中Dialog对话框获取文本文字,只需要使用editor的getText方法就可以获得,示例如下:
final EditText et = new EditText(this);
et.setText(mSharedPreferences.getString("ipadd", "127.0.0.1"));
//获取ip而已,不用在乎
new AlertDialog.Builder(this).setTitle("请输入IP地址")
.setIcon(android.R.drawable.ic_dialog_info).setView(et)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
//数据获取
//Toast.makeText(TestTabActivity.this, et.getText().toString(),
// Toast.LENGTH_LONG).show();
mEditor.putString("ipadd", et.getText().toString());
//关键在这儿,获取输入框的数据,原来很简单!!
mEditor.commit();
}
}).setNegativeButton("取消", null).show();

1、View注意设置成final类型如final View layout=。。。

2、获取文本框对象时候格式EditText e = (EditText)layout.findViewById(R.id);//这里记好了那个layout 是上面final View对象

不注意上面的你就无法获得对话框中的文本了哦!

private void getWifiInfo() {
// TODO Auto-generated method stub
/**
* 当按返回键时的提示对话框,采用默认样式
*/
LayoutInflater inflater=getLayoutInflater();
final View layout=inflater.inflate(R.layout.dialog, (ViewGroup)findViewById(R.id.dialog));

new AlertDialog.Builder(this).
setTitle("自定义布局").
setView(layout).
setPositiveButton("确定",
new DialogInterface.OnClickListener(){ 
@Override 
public void onClick(DialogInterface dialog, int which) { 
EditText et1 = (EditText)layout.findViewById(R.id.wifiname);
EditText et2 =(EditText)layout.findViewById(R.id.wifipassword);
wifiname = et1.getText().toString();
wifipassword=et2.getText().toString();
}})

.setNegativeButton("取消", null).show();

}

实例:

package com.example.mytest;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getdialog();
}
private void getdialog(){
final EditText et=new EditText(this); new AlertDialog.Builder(this).setTitle("请输入面积").setView(et).
setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1){
String size=et.getText().toString();
Log.i("size",size);
}
}).setNegativeButton("取消",null).show();
}
}

android从Dialog对话框中取得文本文字的更多相关文章

  1. 【MFC】MFC改变对话框中静态文本的字体大小

    MFC改变对话框中静态文本的字体大小 2010/08/09 11:30 VC的对话框字体设置对所有控件都有效,你不能单独地改变某个静态文本的字体.对于你的问题,需要首先用CreateFont来建立一个 ...

  2. Android 监听EditView中的文本改变事件

    android中的编辑框EditText也比较常用,那比如在搜索框中,没输入一个字,下面的搜索列表就显示有包含输入关键字的选项,这个输入监听怎么实现的呢? 我们可以建一个例子,效果图如下: 我们可以监 ...

  3. Android自定义 Dialog 对话框

    Android自定义Dialoghttp://www.cnblogs.com/and_he/archive/2011/09/16/2178716.html Android使用自定义AlertDialo ...

  4. 用PDFMiner从PDF中提取文本文字

    1.下载并安装PDFMiner 从https://pypi.python.org/pypi/pdfminer/下载PDFMineer wget https://pypi.python.org/pack ...

  5. 在RichTextBox控件中替换文本文字

    实现效果: 知识运用: RichTextBox控件的SelectedText属性 实现代码: private void button1_Click(object sender, EventArgs e ...

  6. android 原生dialog对话框

    http://www.cnblogs.com/xiaoluo501395377/p/3419398.html

  7. Android中制作自定义dialog对话框的实例

    http://www.jb51.net/article/83319.htm   这篇文章主要介绍了Android中制作自定义dialog对话框的实例分享,安卓自带的Dialog显然不够用,因而我们要继 ...

  8. Android中Dialog对话框

    布局文件xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...

  9. Android UI系列-----Dialog对话框

    您可以通过点击 右下角 的按钮 来对文章内容作出评价, 也可以通过左下方的 关注按钮 来关注我的博客的最新动态. 如果文章内容对您有帮助, 不要忘记点击右下角的 推荐按钮 来支持一下哦 如果您对文章内 ...

随机推荐

  1. CMake 基本用法--写CMakeList.txt

    http://techbase.kde.org/Development/Tutorials/CMake_(zh_CN) http://www.cmake.org/Wiki/CMake 这一章将从软件开 ...

  2. Windows下如何配置tomcat环境变量

    Apache Tomcat 是一款 Java Servlet 和 JavaServer Pages 技术的开源软件实现,可以作为测试 Servlet 的独立服务器,而且可以集成到 Apache Web ...

  3. PHP-表达式

    最精确的定义一个表达式的方式就是"任何有值的东西" $a = 5; 1 > 2;等

  4. vc 6.0 的sdk下载地址

    很多人在为vc6.0sdk版本太老发愁吧,今天在晚上找了半天,终于找到了下载的地方,和大家分享一下. Windows Server 2003 Platform SDKLast Updated: Feb ...

  5. 狄斯奎诺(dijkstra 模板)

    /*狄斯奎诺算法(dijkstra)<邻接表> */ #include<stdio.h> #include<string.h> #include<stdlib ...

  6. 如何用python的装饰器定义一个像C++一样的强类型函数

        Python作为一个动态的脚本语言,其函数在定义时是不需要指出参数的类型,也不需要指出函数是否有返回值.本文将介绍如何使用python的装饰器来定义一个像C++那样的强类型函数.接下去,先介绍 ...

  7. Python实现 K_Means聚类算法

    使用 Python实现 K_Means聚类算法: 问题定义 聚类问题是数据挖掘的基本问题,它的本质是将n个数据对象划分为 k个聚类,以便使得所获得的聚类满足以下条件: 同一聚类中的数据对象相似度较高 ...

  8. 【LeetCode】146. LRU Cache

    LRU Cache Design and implement a data structure for Least Recently Used (LRU) cache. It should suppo ...

  9. matplotlib热图

    1.基础知识点回顾 1.plot(x, y, marker='D')表示绘制折线图,marker设置样式菱形. 2.scatter(x, y, marker='s', color='r')绘制散点图, ...

  10. android studio 中出现"...ProjectScript\buildscript\cache.properties.lock"

      Owner PID: unknownOur PID: 8496Owner Operation: unknownOur operation: Initialize cacheLock file: C ...