StupidBeauty
Read times:574Posted at:Sat Feb 23 19:00:19 2013
- no title specified

转载 android 通过setContentView切换Activity的View,保存动态修改后的视图

可使用LayoutInflator来在运行时动态地将XML布局文件加载为View对象,然后就可以使用这个View对象了。

http://greenboy1.iteye.com/blog/1068482

亮点

public class Main extends Activity {
/** Called when the activity is first created. */
TextView tv1, tv2;
Button b1, b2,b3;
View layout1, layout2;
boolean view2Load=false;//main2是否载入过的flag
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//LayoutInflater inflater = getLayoutInflater();
LayoutInflater inflater = LayoutInflater.from(this);
//以上两行功能一样
layout1 = inflater.inflate(R.layout.main, null);
layout2 = inflater.inflate(R.layout.main2, null);
setView1();
tv1 = (TextView) findViewById(R.id.tv1);
b1 = (Button) findViewById(R.id.b1);
b3 = (Button) findViewById(R.id.b3);
b3.setOnClickListener(l3);
b1.setOnClickListener(l1);
//控件及监听器只需一次查找绑定,切换view不影响
}

private void setView1() {
setContentView(layout1);
//切换到main
}

帐篷征婚

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands

 
Recent comments
2017年4月~2019年4月垃圾短信排行榜Posted at:Thu Sep 26 04:51:48 2024
Qt5.7文档翻译:QWebEngineCookieStore类,QWebEngineCookieStore ClassPosted at:Fri Aug 11 06:50:35 2023盲盒kill -9 18289 Grebe.20230517.211749.552.mp4