LayoutInflater的使用效果和findViewById()有点类似,不过它有更多的功能,具体可以参考api;
代码:
}else if(v.getId()==R.id.dialog_Button){
LayoutInflater inflater = (LayoutInflater) MyGridActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.main_item, null);
EditText txt = (EditText) layout.findViewById(R.id.dia_txt);
txt.setText("Dialog");
Button btn =(Button) layout.findViewById(R.id.dia_btn);
ImageView img = (ImageView) layout.findViewById(R.id.dia_image);
img.setImageResource(R.drawable.super_btn_png1);
Builder builder = new AlertDialog.Builder(MyGridActivity.this);
builder.setView(layout);
AlertDialog dialog = builder.create();
dialog.show();
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
/**
*
*
*/
}
});
dialog_xml:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="4dip" >
<ImageView
android:id="@+id/dia_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/dia_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/dia_image"
android:layout_marginRight="40dp"
android:layout_marginTop="131dp"
android:layout_toLeftOf="@+id/dia_image"
android:text="Button" />
<EditText
android:id="@+id/dia_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<requestFocus />
</EditText>
</RelativeLayout>
效果:
- 大小: 29 KB
分享到:
相关推荐
android inflate demo,方便新手使用,下载导入android studio就可直接运行,简单明了的展现inflate不同参数的区别
Android 中LayoutInflater(布局加载器)之实战篇 博客的Demo 博客地址: http://blog.csdn.net/l540675759/article/details/78112989 两种方式实现小红书的引导页: (1)自定义View (2)自定义LayoutInflater....
最近用到了LayoutInflater这个类,用起来不叫方便,它其实与FindViewById相似,但前者加载的是布局,后者加载的是控件,本人写了一个Demo与大家分享。
private LayoutInflater mInflater;//Context context 从一个Context中,获得一个布局填充器,可以使用这个填充器来把xml布局文件转为View对象//List<ItemBean> list 在构造方法中将数据传进来public MyAdapter...
主要 API : PackageInfo,PackageManager,LayoutInflater,ApplicationInfo PackageManger类,它的主要职责是管理应用程序包。 通过它,我们就可以获取应用程序信息 通过PackageManager获取应用程序相关信息,再...
本文实例讲述了Android编程实现仿美团或淘宝的多级分类菜单效果。分享给大家供大家参考,具体如下: ...View view = LayoutInflater.from(this).inflate(R.layout.popup_layout, null); leftLV = (ListView) view.fin
android:id="@ id/demo_page_list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fadingEdge="none" android:fadingEdgeLength="0px" android:scrollbars=...
可以实现录音,有效率超过百分之九十九 package edu.cmu.pocketsphinx.demo; import java.util.Date; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import ...
LayoutInflater inflater = LayoutInflater.from(mContext); View v = inflater.inflate(R.layout.main, null); addView(v); mArgButton = (Button)v.findViewById(R.id.arg_button); mGlobleButton = ...
drawBitMap之平移佐罗.js dy.js dy抖音评论.js en.js enable.js exec的实践.js fab.js fenduan.js Fermat素性测试.js file_chooser_dialog.js FlashPictureGet(1).js Fuck加密机(不支持注释不支持双斜杠...
demo: public class FragmentPage extends Fragment { View view = null; @Override @SuppressLint(HandlerLeak) public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle ...
Android中图片的左右切换随处可见,今天我也试着查阅资料试着做了一下,挺简单的一个小Demo,却也发现了一些问题,话不多说,上代码~: 使用了3个xml文件作为ViewPager的滑动page,布局都是相同的,如下只展示其中之...
最近实在太忙,一个多礼拜没有更新文章了,于是今晚加班加点把demo写出来,现在都12点了才开始写文章。 1.我们的目标 把RecyclerView下拉刷新上拉加载更多加入到我们的开发者头条APP中。 2.效果图 3.实现步骤 找一...
注:参照大神代码写的 自定义代码 package com.duanlian.popupwindowdemo; import android.app.Activity; import android.content.Context...import android.view.LayoutInflater; import android.view.View; import
在平板上经常能看到这种的情况:左边是一个列表,右边是列表项对应的内容,当点击某一个列表时,右边内容区也会随之改变。下面使用Fragment简单的demo: 思路:在MainActivity定义一个回调接口,并在列表点击回调该...
谷歌官方文档的ViewBinding Demo是用Kotlin语言写的,看起来比较生疏,花了点时间,我在Java上实现了类似的代码,还是看Java比较亲切! 下面简单介绍下如何使用ViewBinding: 修改build.gradle 将 viewBinding 元素...
贡献/下载源码:https://github.com/mmlovesyy/PopupWindowDemo 本文简单模仿微信朋友圈的点赞和评论弹出框,布局等细节请忽略,着重实现弹出框、发评论,及弹出位置的控制。 1. 微信弹出框 微信朋友圈的点赞和评论...
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.color_fragment, container, false); v....
Demo APKgif图片有点模糊,可以扫描下方二维码下载APK体验相关博客ViewPager系列之 仿魅族应用的广告BannerView更新日志v1.1.1 : 增加按住Banner 停止轮播,松开开始自动轮播的功能v1.1.0 : fix 在从网上获取数据...
inflate = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = (LinearLayout)(inflate.inflate(R.layout.item, null)); return new ...