xml的onclick
来源:互联网 发布:淘宝优惠券图片素材 编辑:程序博客网 时间:2024/04/27 20:22
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/btn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按钮1"
android:onClick="mOnButton"/>
<Button
android:id="@+id/btn2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按钮2"
android:onClick="mOnButton"/>
</LinearLayout>
主界面:
package com.issay;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class Test02Activity extends Activity {
/** Called when the activity is first created. */
private Button btn1, btn2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1 = (Button) findViewById(R.id.btn1);
btn2 = (Button) findViewById(R.id.btn2);
}
public void mOnButton(View v) {
switch (v.getId()) {
case R.id.btn1:
Toast.makeText(this, "按钮1", Toast.LENGTH_LONG).show();
break;
case R.id.btn2:
Toast.makeText(this, "按钮2", Toast.LENGTH_LONG).show();
break;
}
}
}
效果图如下:点击按钮1时弹出Toast显示按钮1.点击按钮2相同
- xml的onclick
- android:onClick 的使用 xml调用Java代码
- Android fragment XML中的button找不到Onclick函数的解决方法
- onClick='return onclick()'与 onClick='onclick()'的区别
- onClick='return onclick()'与 onClick='onclick()'的区别
- xml中使用android:onClick
- 安卓showTime and showDate 两个按钮,并在xml中写入相应的onClick方法
- android关于用.xml布局文件中对View添加OnClick事件无法响应的事情
- Android中TextView在xml中设置onClick没用的解决办法
- 在 xml 设置的 onClick 属性 为什么有时候点击不起作用呢?
- button的onclick功能
- Button的onClick属性
- js的onclick事件
- button的onclick事件
- JavaScript的onclick函数
- button的onclick时间
- html的onclick跳转
- TextView在xml里配置onclick事件
- A Bug in Custom ISAPI Filter Related to Keep-Alive
- 一致性 hash 算法( consistent hashing )
- Hadoop分布式文件系统:架构和设计要点
- Extjs4.2 rest 与webapi数据交互
- Spring的作用域以及RequestContextListener作用
- xml的onclick
- 数学专项number_theory:UVa 294
- REST和SOAP
- 深入理解Oracle索引(24):B*Tree 索引小结
- 使用SQL Trace来实现SQL Server的跟踪操作(1)
- C语言的那些小秘密之断言
- 设置文件共享
- [89C51单片机]LCD1602静态显示
- 扯扯淡,写个更快的memcpy