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. arduino~snprintf

    #include <stdio.h> printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf ...

  2. SpringMVC & SpringBoot小记

    SpringMVC 1.SpringMVC常用注解 https://blog.csdn.net/lipinganq/article/details/79155072 :@Component.@Serv ...

  3. NoSQL and Redis

    转自:http://www.cnblogs.com/fxjwind/archive/2011/12/10/2283344.html 首先谈谈为什么需要NoSQL? 这儿看到一篇blog说的不错http ...

  4. 关于VS2013常用到的快捷键

    版本一 VS2013常用快捷键: 1.回到上一个光标位置/前进到下一个光标位置 1)回到上一个光标位置:使用组合键“Ctrl + -”: 2)前进到下一个光标位置:“Ctrl + Shift + - ...

  5. GAN(Generative Adversarial Nets)的发展

    GAN(Generative Adversarial Nets),产生式对抗网络 存在问题: 1.无法表示数据分布 2.速度慢 3.resolution太小,大了无语义信息 4.无reference ...

  6. PHP wamp server问题

    只能说各种不顺,天热人烦! 问题一.wampapache服务不能启动之VCRUNTIME140.DLL文件丢失. 这个是缺少VC运行库,查找并安装相应的文件即可. 问题二.wampapche服务不能启 ...

  7. e575. The Quintessential Drawing Program

    To draw on the screen, it is first necessary to subclass a JComponent and override its paint() metho ...

  8. vc 获取 硬盘序列号 和 cpu

    vc 获取 硬盘序列号 和 cpu 唯一iD的方法?如题---------网上找来很多资料 也没找到, 要支持xp win7 32/64 系统下都能获取 硬盘序列号 和cpu ID 哪位朋友帮帮忙: ...

  9. c++ define的用法(转)

    #define是C语言中提供的宏定义命令,其主要目的是为程序员在编程时提供一定的方便,并能在一定程度上提高程序的运行效率,但学生在学习时往往不能 理解该命令的本质,总是在此处产生一些困惑,在编程时误用 ...

  10. 【Deep learning】NLP

    http://www.tuicool.com/articles/EvaQJnJ http://cs224d.stanford.edu/syllabus.html