一个Activity中使用两个layout实例
package com.sbs.aas2l;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener; public class aas2l extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private String[] data= {"Item-1", "Item-2", "Item-3"};
private Button btn, btn2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
set_aas2l_layout();
}
public void set_aas2l_layout() {
setContentView(R.layout.aas2l);
btn = (Button)findViewById(R.id.pu_btn);
btn.setOnClickListener(this);
btn2 = (Button)findViewById(R.id.exit_btn);
btn2.setOnClickListener(this);
}
public void onClick(View v){
if (v == btn) this.set_pu_layout();
if(v == btn2) this.finish(); }
public void set_pu_layout(){
setContentView(R.layout.pickup);
ListView lv = (ListView)findViewById(R.id.list);
ArrayAdapter<String> arrayAdapter
= new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
lv.setAdapter(arrayAdapter);
lv.setOnItemClickListener(listener);
}
OnItemClickListener listener= new OnItemClickListener(){
public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3){
set_aas2l_layout();
TextView tv = (TextView)findViewById(R.id.tv);
tv.setText("select: " + data[arg2]);
}
};
}
step3。编写ass2l.xml (当然也可以在main.xml中写,这次我新建一个。) <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"> <TextView android:id= "@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dip"
android:text="@string/dialog"
/>
<Button android:id= "@+id/pu_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dip"
android:text="@string/pickup"
/>
<Button android:id= "@+id/exit_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dip"
android:text="@string/exit"
/>
</LinearLayout> step4。编写pickup.xml(点击select按钮后显示的布局,是一个listview。) <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, aas2l"
/>
<ListView android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout> step5。修改strings.xml <?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, aas2l!</string>
<string name="app_name">adroid activity surport 2 layouts</string>
<string name="pickup">select please</string>
<string name="exit">Exit</string>
<string name="dialog">dialog</string>
</resources> step6。运行。 如图: 初始界面 点击select后 选择后 end 。。。。
step3。编写ass2l.xml (当然也可以在main.xml中写,这次我新建一个。) <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"> <TextView android:id= "@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dip"
android:text="@string/dialog"
/>
<Button android:id= "@+id/pu_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dip"
android:text="@string/pickup"
/>
<Button android:id= "@+id/exit_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dip"
android:text="@string/exit"
/>
</LinearLayout> step4。编写pickup.xml(点击select按钮后显示的布局,是一个listview。) <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, aas2l"
/>
<ListView android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout> step5。修改strings.xml <?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, aas2l!</string>
<string name="app_name">adroid activity surport 2 layouts</string>
<string name="pickup">select please</string>
<string name="exit">Exit</string>
<string name="dialog">dialog</string>
</resources> step6。运行。 如图: 初始界面 点击select后 选择后 end 。。。。
一个Activity中使用两个layout实例的更多相关文章
- android开发之Fragment加载到一个Activity中
Fragments 是android3.0以后添加的.主要是为了方便android平板端的开发.方便适应不同大小的屏幕.此代码是为了最简单的Fragment的使用,往一个Activity中添加Frag ...
- ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法
ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法 语法 第一种: 通过使用Oracle语句块 --指定文档所有部门都能查看 declare cursor TABLE_DEPT and ...
- JS 从一个字符串中截取两个字符串之间的字符串
/************************************************* 函数说明:从一个字符串中截取 两个字符串之间的字符串 参数说明:src_str 原串, start ...
- C语言:一个数组中只有两个数字是出现一次
//1.一个数组中只有两个数字是出现一次, //其他所有数字都出现了两次. //找出这两个数字,编程实现.a //^=单独两个数的^结果 //单独出现的两个数不同位的标记 //position: ^结 ...
- 一个线程中lock用法的经典实例
/* 该实例是一个线程中lock用法的经典实例,使得到的balance不会为负数 同时初始化十个线程,启动十个,但由于加锁,能够启动调用WithDraw方法的可能只能是其中几个 作者:http://h ...
- Android studio 一个项目中添加两个module遇到的bug
1.在一个Android studio中,我添加了一个模块,然后就是各种bug 找到到R 是在module 名上面 右键 Make Module '模块名' 经过各种google 的时候发现了 htt ...
- 当一个activity中按钮过多时怎么办?
这几天看极客学院的视频,跟视频中的老师学到的一些小技巧~~ .setOnClickListener(this) 通过重写this(我猜的是重写),下面有onClicked() package exam ...
- C#把某个数组的一部分复制到另一个数组中的两种方法:Buffer.BlockCopy和Array.Copy
static void Main(string[] args) { , , , , , }; ;//目标数组大小 int int_size = sizeof(int);//用于获取值类型的字节大小. ...
- 两个表,一个表中的两列关联另一个表的id,如何将这个表中的两列显示为另一个表id对应的内容
表A name user owner machine1 1 2 machine2 3 4 表B userid username 1 aaa 2 bbb 3 ccc 4 ddd 以上两个表,表A 设备的 ...
随机推荐
- Html5 小球键盘移动
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- 验证url 地址是否是图片
由于正则不是很熟悉 所以面对这样的目前只能采取两步走 一 判断url地址是否是正确的http 二判断后缀是否是图片 格式 /驗證URL function validUrl(strUrl){ strUr ...
- delete指针以后应赋值为NULL——QT deletelater指针以后也同样要马上赋值为NULL
delete p后,只是释放了指针指向的内存空间.p并不会自动被置为NULL,而且指针还在,同时还指向了之前的地址 delete NULL编译器不会报错(因为delete空指针是合法的) 例: 对一个 ...
- goto 语句
goto 语句 自从提倡结构化设计以来,goto 就成了有争议的语句. 首先,由于 goto 语句可以 灵活跳转,如果不加限制,它的确会破坏结构化设计风格.其次,goto 语句经常带来错 误或隐患. ...
- 【转载】ASP.NET Core 中间件详解及项目实战
前言 在上篇文章主要介绍了DotNetCore项目状况,本篇文章是我们在开发自己的项目中实际使用的,比较贴合实际应用,算是对中间件的一个深入使用了,不是简单的Hello World,如果你觉得本篇文章 ...
- (转)loff_t *ppos是什么东东
ssize_t generic_file_read(struct file * filp, char * buf, size_t count, loff_t *ppos) 这是一个文件读函数 我们很容 ...
- (转载)UTF-8和GBK的编码方式的部分知识:重要
GBK的文字编码是双字节来表示的,即不论中.英文字符均使用双字节来表示,只不过为区分中文,将其最高位都定成1. 至于UTF-8编码则是用以解决国际上字符的一种多字节编码,它对英文使用8位(即一个字节) ...
- 前台的js对象数组传到后台处理。在前台把js对象数组转化为json字符串,在后台把json字符串解析为List<>
前台的js对象数组传到后台处理.在前台把js对象数组转化为json字符串,在后台把json字符串解析为List<>
- 【python】通过代理安装包
1.安装setuptools 支持 pip install 或easy_install 2.在终端执行 set HTTP_PROXY=http://your.proxy.com:yourPort se ...
- OpenCV学习:图像的载入和显示
一.使用IplImage结构读取并显示图像文件: 运行结果: 二.使用Mat类读取并显示图像文件: 使用 Mat 类,内存管理变得简单,不再像使用 IplImage 那样需要自己申请和释放内存,而且一 ...