Android 在其他类中获取某个activity类中的布局和Id

来源:互联网 发布:新浪邮箱 端口 编辑:程序博客网 时间:2024/05/06 12:46
layout为布局,布局里面可以放任何空间,获取空间可以用findViewById方法获取android 获取某个布局控件 添加到另一个布局中
LayoutInflater factorys = LayoutInflater.from(MainActivity.this);//获取MainActivity中LayoutInflater (上下文参数)View view= factorys.inflate(R.layout.layout1, null);//获取View 对象
EditText editText1 = (EditText) view.findViewById(R.id.editText1);
Ps:android中各个组件相当于大树上的树枝,果,叶子。想要获取什么,首先要告诉系统你需要什么种类的“树”-布局
0 0
原创粉丝点击