Android游戏开发系统控件-Button
来源:互联网 发布:喜欢英国的理由 知乎 编辑:程序博客网 时间:2024/05/21 14:58
Android游戏开发系统控件-Button
Button(按钮)是一个常用的系统小组件,很小但是在开发中最常用到。一般通过与监听器使用,从而触发一些特定事件。
下面为一个Andriod项目“ButtonProject”,对应的代码如下
作者:wwj
项目功能:点击按钮触发事件
代码分别为:
main.xml
string.xml
ButtonProject.java
项目运行效果图:
代码清单:
=》》main.xml
<?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:id="@+id/tv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/btn_ok" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/btn_ok" /> <Button android:id="@+id/btn_cancel" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/btn_cancel" /></LinearLayout>
=》》string.xml
<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello World, ButtonProject!</string> <string name="app_name">ButtonProject</string> <string name="btn_ok">确定</string> <string name="btn_cancel">取消</string></resources>
=》》ButtonProject.java
package com.buttonProject;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class ButtonProject extends Activity implements OnClickListener{private Button btn_ok,btn_cancel;//声明两个按钮对象private TextView tv;//声明文本视图对象 /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //对btn_ok对象进行实例化 btn_ok = (Button) findViewById(R.id.btn_ok); //对btn_cancel对象进行实例化 btn_cancel = (Button) findViewById(R.id.btn_cancel); //对tv对象进行实例化 tv =(TextView) findViewById(R.id.tv); //将btn_ok按钮绑定在点击监听器上 btn_ok.setOnClickListener(this); //将btn_cancel按钮绑定在点击监听器上 btn_cancel.setOnClickListener(this); } //使用点击监听器必须重写其抽象函数, public void onClick(View v) {// TODO Auto-generated method stub if(v == btn_ok){ tv.setText("确定按钮触发事件!"); }else if(v == btn_cancel){ tv.setText("取消按钮触发事件!"); }}}
package com.buttonProject;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class ButtonProject extends Activity implements OnClickListener{private Button btn_ok,btn_cancel;//声明两个按钮对象private TextView tv;//声明文本视图对象 /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //对btn_ok对象进行实例化 btn_ok = (Button) findViewById(R.id.btn_ok); //对btn_cancel对象进行实例化 btn_cancel = (Button) findViewById(R.id.btn_cancel); //对tv对象进行实例化 tv =(TextView) findViewById(R.id.tv); //将btn_ok按钮绑定在点击监听器上 btn_ok.setOnClickListener(this); //将btn_cancel按钮绑定在点击监听器上 btn_cancel.setOnClickListener(this); } //使用点击监听器必须重写其抽象函数, public void onClick(View v) {// TODO Auto-generated method stub if(v == btn_ok){ tv.setText("确定按钮触发事件!"); }else if(v == btn_cancel){ tv.setText("取消按钮触发事件!"); }}}
- Android游戏开发系统控件-Button
- 3.Android 游戏开发常用的系统控件(Button、Layout、ImageButton)
- 【读书笔记《Android游戏编程之从零开始》】3.Android 游戏开发常用的系统控件(Button、Layout、ImageButton)
- Android游戏开发系统控件-ImageButton
- Android游戏开发系统控件-EditText
- Android游戏开发系统控件-CheckBox
- Android游戏开发系统控件-ProgressBar
- Android游戏开发系统控件-ListView
- Android游戏开发系统控件-Dialog
- Android游戏开发系统控件-CheckBox
- Android 控件开发之Button
- Android 控件开发之Button
- Android游戏开发系统控件-TabSpec与TabHost
- 7.Android 游戏开发常用的系统控件(Dialog)
- Android开发之自定义控件-自定义Button
- Android UI开发中的常用控件Button
- 【读书笔记《Android游戏编程之从零开始》】8.Android 游戏开发常用的系统控件(系统控件常见问题)
- 【读书笔记《Android游戏编程之从零开始》】7.Android 游戏开发常用的系统控件(Dialog)
- IntentFilter分析
- 《无鳔的鱼》
- poj 3233 矩阵快速幂 + 二分求和
- 【C++问题总结】尽量减少使用宏,因为即使加了括号也可能会出问题
- Android中滑屏实现----手把手教你如何实现触摸滑屏以及Scroller类详解
- Android游戏开发系统控件-Button
- App列表之圆角ListView源码
- linux下安装使用phpMyAmin
- 生成指定版本的Rails项目
- 用C++程序求解“谁养鱼”
- 上手GM8126的经历
- ubuntu下解决由于错误配置分辨率导致黑屏问题
- WM_NOTIFY
- GB,GBC,GBA游戏模拟器移植心得