- 1、本文档共11页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
控件的OnClick属性,设置点击事件的响应方法名android:onClick=”方法名”
缺点:当类的代码较多,方法和内部类较多时,代码管理不方便
优点:屏蔽所有的内部机制,不需要掌握回调机机制,学习测试阶段用(程序规模很小)
Activity_main.xml
LinearLayout xmlns:android=/apk/res/android
xmlns:tools=/tools
android:layout_width=match_parent
android:layout_height=match_parent
android:orientation=vertical
Button
android:id=@+id/btn_Framelayout
android:layout_width=match_parent
android:layout_height=wrap_content
android:text=用表格布局实现注册
android:onClick=framelayout/
Button
android:id=@+id/btn_Gridlayout
android:layout_width=match_parent
android:layout_height=wrap_content
android:text=用网格布局实现注册
android:onClick=gridlayout/
Button
android:id=@+id/btn_Linearlayout
android:layout_width=match_parent
android:layout_height=wrap_content
android:text=用线性布局实现注册
android:onClick=linearlayout/
Button
android:id=@+id/btn_Relativelayout
android:layout_width=match_parent
android:layout_height=wrap_content
android:text=用绝对布局实现注册
android:onClick=relativelayout/
Button
android:id=@+id/btn_Tablelayout
android:layout_width=match_parent
android:layout_height=wrap_content
android:text=用表格布局实现注册
android:onClick=tablelayout/
/LinearLayout
MainActivity.java
package com.example.day03_03;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void framelayout(View f) {
setContentView(R.layout.framelayout);
}
//下面是 onClick值是gridLayout的按钮的点击事件响应的方法
public void gridlayout(View g) {
Log.i(Main, ((Button)g).getText().toString());
//Main是LogCat里已存在的过滤器名
setContentView(R.layout.gridlayout);
}
public void linearlayout(View l) {
setContentView(R.layout.linearlayout);
}
public void
您可能关注的文档
- 2015年灾害预防与处理计划详解.doc
- 2523中央电大汽修专业《汽车电子技术基础与电路》期末复习题详解.doc
- 2015年造价员考前培训基础知识_new详解.doc
- 2604欧陆控制器_new详解.doc
- 2015年招教公基串讲讲义详解.doc
- 2604欧陆控制器详解.doc
- 2015年浙大远程物理化学离线必做作业_new详解.doc
- 2015年浙大远程物理化学离线必做作业详解.doc
- 2015年浙江高考理科综合(含答案word版)_new详解.doc
- 3000高频词汇_new详解.doc
- 2025年3月公司、局党组深入贯彻中央八项规定精神学习教育工作方案.docx
- 2025年4月 纪检监察干部关于深入贯彻中央八项规定精神学习教育的研讨发言材料.docx
- 在2025年深入贯彻中央八项规定精神学习教育动员部署会上的讲话提纲+中央八项规定精神学习教育学习计划(2025年3月-7月).doc
- 2025年中央八项规定精神学习教育专题党课:推动作风建设走深走实.docx
- 4篇 2025年3月-7月关于开展深入贯彻中央八项规定精神学习教育的实施方案.docx
- 县委常委班子2024年度民主生活会整改方案+党支部2024年组织生活会主持词.docx
- 2025年学习二十届中央纪委四次全会工作报告心得体会.docx
- 3篇 2025年学习贯彻第十九次集体学习重要讲话心得体会.docx
- 2025年3月—2026年2月中小学校“中央八项规定精神学习年”工作计划+2025年3月-7月深入中央八项规定精神学习教育学习计划表.doc
- 2025年学习贯彻二十届中央纪委四次全会精神专题廉政党课讲稿:以革新精神与严正标准推动全面从严治党、推进全市纪检监察工作高质量发展.docx
文档评论(0)