Android开发之onClick(鼠标点击)事件的三种写法
来源:互联网 发布:波士顿矩阵分析法例题 编辑:程序博客网 时间:2024/06/05 17:44
- package a.a;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- public class AActivity extends Activity {
- /** Called when the activity is first created. */
- EditText Ev1;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Ev1 = (EditText)findViewById(R.id.editText1);
- //第一种方式
- Button Btn1 = (Button)findViewById(R.id.button1);//获取按钮资源
- Btn1.setOnClickListener(new Button.OnClickListener(){//创建监听
- public void onClick(View v) {
- String strTmp = "点击Button01";
- Ev1.setText(strTmp);
- }
- });
- //第二种方式
- Button Btn2 = (Button) findViewById(R.id.button2);//获取按钮资源
- Btn2.setOnClickListener(listener);//设置监听
- }
- Button.OnClickListener listener = new Button.OnClickListener(){//创建监听对象
- public void onClick(View v){
- String strTmp="点击Button02";
- Ev1.setText(strTmp);
- }
- };
- //第三种方式(Android1.6版本及以后的版本中提供了)
- public void Btn3OnClick(View view){
- String strTmp="点击Button03";
- Ev1.setText(strTmp);
- }
- }
- <?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/button1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Button1" />
- <Button
- android:id="@+id/button2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Button2" />
- <Button
- android:id="@+id/button3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Button3"
- android:onClick="Btn3OnClick"/>
- <EditText
- android:id="@+id/editText1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" >
- <requestFocus />
- </EditText>
- </LinearLayout>
0 1
- Android开发之onClick(鼠标点击)事件的三种写法
- Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- Android 开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- 转:Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- Android开发之onClick事件的三种写法
- QTP+QC测试框架
- 【整合篇】Activiti业务与流程整合之查询(三)
- Unity中关于保存图片到Android/IOS相册中的问题
- FlowDroid: 精确的上下文,流,字段, 对象敏感和生存周期感知的污染分析
- python调用Shell脚本(或其他脚本比如python)
- Android开发之onClick(鼠标点击)事件的三种写法
- NYOJ 1156 素数三元组【尝试题】
- 单例模式之窗体显示
- 尝试写博客
- 一步一步写算法(之hash表)
- 三层问题集锦
- Project 7:自然数的拆分
- 优秀程序员应该具备的12种能力
- 操作系统概论