Android开发笔记(11)——DialogFragment & 点击监听
转载请注明:http://www.cnblogs.com/igoslly/p/6931519.html
DialogFragment使用 & 点击监听
/* DialogFragment是用于Activity上展示一个界面的弹出框,如输入框、警告框、确认框等
* DialogFragment单独设置layout XML文件
* 使用DialogFragment至少需要实现onCreateView或者onCreateDIalog方法;
* onCreateView即使用定义的xml布局文件展示Dialog
* onCreateDialog即利用AlertDialog或者Dialog创建出Dialog。
*/
下面给出我自己写的几个实例:
1、修改姓名的输入框
布局文件:
1、输入的EditBox控件,用于输入新用户名
2、确认的ImageView,点击监控并获取输入字符
3、退出的Button按钮,不做任何修改
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:hint="Please enter new user name ..."
android:inputType="text"
android:id="@+id/opponent_name_edit"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_edit"
android:id="@+id/opponent_name_confirm"/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BACK"
android:textSize="24sp"
android:layout_marginTop="10dp"
android:id="@+id/edit_dialog_back"/>
</LinearLayout>
2、选择内容的点击框
/* DialogFragment活动设置和一般Fragment相同
* 我一般采用onCreateView方法
*/
public class EditDialogue extends DialogFragment { private EditText mNewNameEditText;
private ImageView mNewNameConfirm;
private String player; @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ View rootView =inflater.inflate(R.layout.opponent_name_edit,container);
mNewNameEditText = (EditText) rootView.findViewById(R.id.opponent_name_edit);
mNewNameConfirm = (ImageView) rootView.findViewById(R.id.opponent_name_confirm); Button backButton = (Button) rootView.findViewById(R.id.edit_dialog_back);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
player="";
dismiss();
}
});
mNewNameConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
player = mNewNameEditText.getText().toString();
setData();dismiss();
}}); return rootView;
}
}
/* 点击检测
* 通常的按钮点击可以在XML文件设置Onclick属性,直接调用MainActivity方法
*/
anroid:OnClick="RecordName"
//Activity中设置函数
public void RecordName(View view){
EditBox editbox = findViewById(R.id.name_edit);
String newName = editbox.getText().toString(); // 此处getText()获取为Editable类型,toString()转换
}
/* 点击检测
* Fragment里则采用OnclickLisener而进行监听
* OnclickLisener是View类的函数,故而不仅对Button,对继承于View的控件均可采用
* 输入框中同时也对ImageView进行了监听,并发送数据关闭Dialog
*/
mNewNameConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
player = mNewNameEditText.getText().toString();
setData();dismiss();
}});
本笔记内容均为个人学习整理,转载请注明博客园-igoslly
Android开发笔记(11)——DialogFragment & 点击监听的更多相关文章
- Android开发 ---基本UI组件5:监听下拉选项,动态绑定下拉选项、全选/反选,取多选按钮的值,长按事件,长按删除,适配器的使用,提示查询数据,activity控制多按钮
效果图: 效果描述: 1.当点击 1 按钮后,进入选择城市的页面,会监听到你选中的城市名称:动态为Spinner绑定数据 2.当点击 2 按钮后,进入自动查询数据页面,只要输入首字母,就会动态查找以该 ...
- [置顶] Android开发笔记(成长轨迹)
分类: 开发学习笔记2013-06-21 09:44 26043人阅读 评论(5) 收藏 Android开发笔记 1.控制台输出:called unimplemented OpenGL ES API ...
- 【转】Android开发笔记(序)写在前面的目录
原文:http://blog.csdn.net/aqi00/article/details/50012511 知识点分类 一方面写写自己走过的弯路掉进去的坑,避免以后再犯:另一方面希望通过分享自己的经 ...
- Android开发笔记(一百三十四)协调布局CoordinatorLayout
协调布局CoordinatorLayout Android自5.0之后对UI做了较大的提升.一个重大的改进是推出了MaterialDesign库,而该库的基础即为协调布局CoordinatorLayo ...
- 《ArcGIS Runtime SDK for Android开发笔记》
开发笔记之基础教程 ArcGIS Runtime SDK for Android 各版本下载地址 <ArcGIS Runtime SDK for Android开发笔记>——(1).And ...
- 《ArcGIS Runtime SDK for Android开发笔记》——离在线一体化技术:离线矢量数据同步
1.前言 上一篇文章中我们实现了离线要素的编辑操作,这一篇中主要介绍离在线一体化技术中最后一个环节离线数据的同步功能,通过对数据的上传,服务器端的版本化管理,实现数据生产管理的整个流程. 转载请注明出 ...
- 《ArcGIS Runtime SDK for Android开发笔记》——(7)、示例代码arcgis-runtime-samples-android的使用
1.前言 学习ArcGIS Runtime SDK开发,其实最推荐的学习方式是直接看官方的教程.示例代码和帮助文档,因为官方的示例一般来说都是目前技术最新,也是最详尽的.对于ArcGIS Runtim ...
- Android开发笔记:打包数据库
对于数据比较多的控制一般会加入SQLite数据库进行数据存储,在打包时这些数据库是不自动打包到apk中的,如何创建数据库呢 方法1:将创建数据库的sql语句在SQLiteHelper继承类中实现,在第 ...
- Android开发笔记--hello world 和目录结构
原文:Android开发笔记--hello world 和目录结构 每接触一个新东西 都有一个hello world的例子. 1.新建项目 2.配置AVD AVD 没有要新建个,如果不能创建 运行SD ...
随机推荐
- PAT 1111 Online Map
Input our current position and a destination, an online map can recommend several paths. Now your jo ...
- pip操作以及window和虚拟机中为pip更换一个国内的镜像源的方法
前言 在学习PyQt5的过程中,参考王硕和孙洋洋的PyQt5快速开发与实战中,看到的关于Python开发技巧与实战,觉得挺好的 所以将其摘抄了下来方便阅读.之后还有一个关于更换pip镜像源的方法,方便 ...
- Jquery书写ajax
根据API学习本章 Jquery书写ajax 使用ajax发送表单到servlet,发送时显示等待图片,servlet处理完返回信息,在页面显示返回信息,并且隐藏等待图片 <%@ page la ...
- Performance Metrics(性能指标1)
Performance Metrics(性能指标) 在我们开始旅行本书之前,我必须先了解本书的性能指标和希望优化后的结果,在第二章中,我们探索更多的性能检测工具和性能指标,可是,您得会使用这些工具和明 ...
- MVC.Net:读取Web.config/App.config配置
需要读取Web.config/App.config的配置很简单,首先我们需要将配置写入到<appSettings>中,例如: <appSettings> <add key ...
- Python图像处理库PIL中图像格式转换(一)
在数字图像处理中,针对不同的图像格式有其特定的处理算法. 所以,在做图像处理之前,我们须要考虑清楚自己要基于哪种格式的图像进行算法设计及事实上现.本文基于这个需求.使用python中的图像处理库PIL ...
- Hadop使用Partitioner后,结果还是一个文件,怎样解决??
近期看了一下partitioner.于是照着写了一个列子.最后发现程序并没有将结果分开写入对应的文件,结果还是一个文件,于是乎感觉是不是没实用集群去执行程序,发现control中还是本地执行的代码: ...
- ExtJs 日期相加,Grid表格列可编辑
1.日期相加: Ext.Date.add(new Date(), Ext.Date.DAY, 15) 2.Grid表格列可编辑: { header : "实际已交货量", ...
- LESS2CSS for sumlime text2
Windows下的安装 Less2Css插件依赖lessc这个工具,在windows下可以下载或者用git cloneless.js-windows到本地目录.然后把目录地址加入到环境变量PATH的中 ...
- maven工程读取resource下配置文件
maven工程读取resource下配置文件 在maven工程中,我们会将配置文件放到,src/main/resources 下面,例如 我们需要确认resource 下的文件 编译之后存放的位置 ...