博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
include的用法例子,以及include+merge的用法例子
阅读量:5818 次
发布时间:2019-06-18

本文共 3033 字,大约阅读时间需要 10 分钟。

【include+LinearLayout】的使用例子

AndroidIncludeLayout.java

package com.AndroidIncludeLayout; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class AndroidIncludeLayout extends Activity {          @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);                  View subLayout1 = (View)findViewById(R.id.main1);         View subLayout2 = (View)findViewById(R.id.main2);         Button myButton_main1 = (Button)subLayout1.findViewById(R.id.mybutton);         Button myButton_main2 = (Button)subLayout2.findViewById(R.id.mybutton);         Button startAnotherActivity = (Button)findViewById(R.id.startanotheractivity);                  startAnotherActivity.setOnClickListener(new Button.OnClickListener(){    @Override    public void onClick(View arg0) {     // TODO Auto-generated method stub     Intent intent = new Intent();              intent.setClass(AndroidIncludeLayout.this, AnotherActivity.class);              startActivity(intent);         }});                  myButton_main1.setOnClickListener(new Button.OnClickListener(){    @Override    public void onClick(View arg0) {     // TODO Auto-generated method stub     Toast.makeText(AndroidIncludeLayout.this, "Button 1 Pressed", Toast.LENGTH_LONG).show();    }});                  myButton_main2.setOnClickListener(new Button.OnClickListener(){    @Override    public void onClick(View arg0) {     // TODO Auto-generated method stub     Toast.makeText(AndroidIncludeLayout.this, "Button 2 Pressed", Toast.LENGTH_LONG).show();    }});     } }

 

mail.xml 

sublayout.xml 

 

 

 

 

 

 

 

【include+merge】   //与上面的include用法有点不一样

LightActivity.java

/** * Copyright(c) 2014-2015 ChinaYong Hotel Media Technology Co.,Ltd. * All Rights Reserved. *  * Filename : LightActivity.java * Author : Seldy lipeineng * Creation time : 上午10:58:53 - 2015-6-4 * Description : */package com.hysmarthotel.roomcontrol;import com.hysmarthotel.util.LogUtil;import com.hysmarthotel.view.Temperature;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.TextView;//灯光控制public class LightActivity extends Activity {    public static Temperature temp;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.light);        temp = (Temperature)findViewById(R.id.temperature_light);  //特殊的地方是,可以直接一步调用merge中的id,不用通过include,再去调用        log("layout1"+temp);        init();    }    private void init() {        temp.setTemperature(MainActivity.mTemp+"");    }    private void log(String msg) {        LogUtil.info(this.getClass(), this + ":" + msg,"i");    }}

 

light.xml

 

time_temp.xml

 

转载于:https://www.cnblogs.com/lipeineng/p/5215988.html

你可能感兴趣的文章
MySQL 备份与恢复
查看>>
TEST
查看>>
PAT A1037
查看>>
(六)Oracle学习笔记—— 约束
查看>>
[Oracle]如何在Oracle中设置Event
查看>>
top.location.href和localtion.href有什么不同
查看>>
Gradle之module间依赖版本同步
查看>>
java springcloud版b2b2c社交电商spring cloud分布式微服务(十五)Springboot整合RabbitMQ...
查看>>
d3 v4实现饼状图,折线标注
查看>>
微软的云策略
查看>>
Valid Parentheses
查看>>
ES6的 Iterator 遍历器
查看>>
nginx 301跳转到带www域名方法rewrite(转)
查看>>
AIX 配置vncserver
查看>>
windows下Python 3.x图形图像处理库PIL的安装
查看>>
【IL】IL生成exe的方法
查看>>
SettingsNotePad++
查看>>
centos7安装cacti-1.0
查看>>
没有JS的前端:体积更小、速度更快!
查看>>
数据指标/表现度量系统(Performance Measurement System)综述
查看>>