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实例的更多相关文章

  1. android开发之Fragment加载到一个Activity中

    Fragments 是android3.0以后添加的.主要是为了方便android平板端的开发.方便适应不同大小的屏幕.此代码是为了最简单的Fragment的使用,往一个Activity中添加Frag ...

  2. ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法

    ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法 语法 第一种: 通过使用Oracle语句块  --指定文档所有部门都能查看 declare cursor TABLE_DEPT and ...

  3. JS 从一个字符串中截取两个字符串之间的字符串

    /************************************************* 函数说明:从一个字符串中截取 两个字符串之间的字符串 参数说明:src_str 原串, start ...

  4. C语言:一个数组中只有两个数字是出现一次

    //1.一个数组中只有两个数字是出现一次, //其他所有数字都出现了两次. //找出这两个数字,编程实现.a //^=单独两个数的^结果 //单独出现的两个数不同位的标记 //position: ^结 ...

  5. 一个线程中lock用法的经典实例

    /* 该实例是一个线程中lock用法的经典实例,使得到的balance不会为负数 同时初始化十个线程,启动十个,但由于加锁,能够启动调用WithDraw方法的可能只能是其中几个 作者:http://h ...

  6. Android studio 一个项目中添加两个module遇到的bug

    1.在一个Android studio中,我添加了一个模块,然后就是各种bug 找到到R 是在module 名上面 右键 Make Module '模块名' 经过各种google 的时候发现了 htt ...

  7. 当一个activity中按钮过多时怎么办?

    这几天看极客学院的视频,跟视频中的老师学到的一些小技巧~~ .setOnClickListener(this) 通过重写this(我猜的是重写),下面有onClicked() package exam ...

  8. C#把某个数组的一部分复制到另一个数组中的两种方法:Buffer.BlockCopy和Array.Copy

    static void Main(string[] args) { , , , , , }; ;//目标数组大小 int int_size = sizeof(int);//用于获取值类型的字节大小. ...

  9. 两个表,一个表中的两列关联另一个表的id,如何将这个表中的两列显示为另一个表id对应的内容

    表A name user owner machine1 1 2 machine2 3 4 表B userid username 1 aaa 2 bbb 3 ccc 4 ddd 以上两个表,表A 设备的 ...

随机推荐

  1. LINQ操作符三:限制操作符

    where是限制操作符,它将过滤标准应用在序列上,按照提供的逻辑对序列中的数据进行过滤. where操作符不启动查询的执行.当开始对序列进行遍历时才开始执行,此时过滤条件将被应用到查询中. 示例: / ...

  2. 分享10个原生JavaScript技巧

    首先在这里要非常感谢无私分享作品的网友们,这些代码片段主要由网友们平时分享的作品代码里面和经常去逛网站然后查看源文件收集到的.把平时网站上常用的一些实用功能代码片段通通收集起来,方便网友们学习使用,利 ...

  3. 数组累加兼eval性能测试

    <label> <input type="checkbox" />测试结果 </label> <script> document.g ...

  4. MapReduce生成HFile入库到HBase

    转自:http://www.cnblogs.com/shitouer/archive/2013/02/20/hbase-hfile-bulk-load.html 一.这种方式有很多的优点: 1. 如果 ...

  5. HttpComponents 基础接口/类与HTTP message的对应关系

    前提一: 什么是HTTP Message -- 遵循HTTP协议发送的消息!其格式是固定的:HTTP Message = Message Line + Message Header + Message ...

  6. error: expected declaration specifiers or '...' before 'xxxx'(xxxx是函数形参)

    今天汗颜了一大阵 早上,在编译我的源代码的时候竟然不通过编译,上个星期六也出现了这种情况,当时不知道怎么弄的后来又通过编译了,可能是原来的.o文件没有make clean 还保存在那里,以至于蒙过去了 ...

  7. 创建以API为中心的Web应用(转)

    英文原文:Creating an API-Centric Web Application 引言 API——API是Application Programming Interface(应用编程接口)的简 ...

  8. linux源代码编译安装OpenCV

    为了尽可能保证OpenCV的特性,使用OpenCV源代码编译安装在linux上.先从安装其依赖项開始,以ubuntu 14.04.X为例解说在Linux上源代码编译安装OpenCV,其它linux版本 ...

  9. opengl 裁剪平面

    原帖地址:http://blog.sina.com.cn/s/blog_5ff6097b0100xqvr.html void glClipPlane(GLenum plane, const GLdou ...

  10. Oracle 添加主键和索引

    数据的主键和索引一般情况下都是必须的,特别是表有大量数据的时候,索引和主键更是必不可少,这样可以提供数据的查询效率: 一.创建表的同时创建主键约束 (1)无命名 create table studen ...