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 ...
随机推荐
- vue 微信授权解决方案
背景 前后端分离项目 - SpringSocial 绑定与解绑社交账号如微信.QQ2018-08-14更新时隔四个月第一次更新,因为项目重构有一次接触到了微信授权,思路已经比原来清晰的多了,将重新修改 ...
- TypeError与ValueError的区别
typeerror:函数或方法接受了不适当的[类型]的参数,比如sum('nick'),sum函数不接受字符串类型:valueerror:函数或方法虽然接受了正确的[类型]的参数,但是该参数的[值]不 ...
- saving snaps iteratively with for loop in Paraview
Goal: read data 1 and slice, then save pressure, velocity contours, close data, then do loop for the ...
- hdu 2782 dfs(限定)
The Worm Turns Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Spring 源代码学习(一)
一 .Spring容器最基本的功能 1. 读取配置文件 2. 校验配置文件的正确性 3. 将配置文件信息加载到内存 4. 通过反射实例化bean对象 5. 构建系统 二 .核心类关系图 图1-1 D ...
- 【Codeforces 467C】George and Job
[链接] 我是链接,点我呀:) [题意] 让你从1..n这n个数字中 选出来k个不相交的长度为m的区间 然后这个k个区间的和最大 求出这k个区间的和的最大值 [题解] 设dp[i][j]表示前i个数字 ...
- 【Codeforces 158A】Next Round
[链接] 我是链接,点我呀:) [题意] 让你找到排名的前k名,并列的话,如果分数大于0那么就算晋级 问你最后有多少人可以晋级. [题解] 按照题意模拟就好, 先按照a[max] = a[k]的规则找 ...
- 【codeforces 514A】Chewbaсca and Number
[题目链接]:http://codeforces.com/contest/514/problem/A [题意] 允许你把每个数字翻转 ->x变成9-x 然后问你能够变成的最小的数字是什么; 不能 ...
- Linux学习总结(3)——Linux实用工具
1. Windows下同步Linux文件(Linux安装Samba和配置) 场景需求: 安装了Ubuntu在虚拟机上,但是代码编辑或者其它更多的操作的时候,还是习惯在windows下进行.如果wind ...
- detecting locked tables mysql (locked by LOCK TABLE)
detecting locked tables mysql (locked by LOCK TABLE) up vote15down votefavorite 7 I would like to kn ...