你好,游客 登录 注册 搜索
背景:
阅读新闻

Android游戏开发系统控件-Button

[日期:2012-05-13] 来源:Linux社区  作者:wwj [字体:大 中 小]

=》》string.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.   
  4.     <string name="hello">Hello World, ButtonProject!</string>  
  5.     <string name="app_name">ButtonProject</string>  
  6.     <string name="btn_ok">确定</string>  
  7.     <string name="btn_cancel">取消</string>  
  8.   
  9. </resources>  

=》》ButtonProject.java

  1. package com.buttonProject;  
  2.   
  3. import Android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.view.View;  
  6. import android.view.View.OnClickListener;  
  7. import android.widget.Button;  
  8. import android.widget.TextView;  
  9.   
  10.   
  11. public class ButtonProject extends Activity implements OnClickListener{  
  12.     private Button btn_ok,btn_cancel;   //声明两个按钮对象   
  13.     private TextView tv;    //声明文本视图对象   
  14.     /** Called when the activity is first created. */  
  15.     @Override  
  16.     public void onCreate(Bundle savedInstanceState) {  
  17.         super.onCreate(savedInstanceState);  
  18.         setContentView(R.layout.main);  
  19.         //对btn_ok对象进行实例化   
  20.         btn_ok = (Button) findViewById(R.id.btn_ok);  
  21.         //对btn_cancel对象进行实例化   
  22.         btn_cancel = (Button) findViewById(R.id.btn_cancel);  
  23.         //对tv对象进行实例化   
  24.         tv =(TextView) findViewById(R.id.tv);  
  25.         //将btn_ok按钮绑定在点击监听器上   
  26.         btn_ok.setOnClickListener(this);  
  27.         //将btn_cancel按钮绑定在点击监听器上   
  28.         btn_cancel.setOnClickListener(this);  
  29.     }  
  30.     //使用点击监听器必须重写其抽象函数,   
  31.     public void onClick(View v) {  
  32.         // TODO Auto-generated method stub   
  33.         if(v == btn_ok){  
  34.             tv.setText("确定按钮触发事件!");  
  35.         }else if(v == btn_cancel){  
  36.             tv.setText("取消按钮触发事件!");  
  37.         }     
  38.     }  
  39. }  

 

  1. package com.buttonProject;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.view.View;  
  6. import android.view.View.OnClickListener;  
  7. import android.widget.Button;  
  8. import android.widget.TextView;  
  9.   
  10.   
  11. public class ButtonProject extends Activity implements OnClickListener{  
  12.     private Button btn_ok,btn_cancel;   //声明两个按钮对象   
  13.     private TextView tv;    //声明文本视图对象   
  14.     /** Called when the activity is first created. */  
  15.     @Override  
  16.     public void onCreate(Bundle savedInstanceState) {  
  17.         super.onCreate(savedInstanceState);  
  18.         setContentView(R.layout.main);  
  19.         //对btn_ok对象进行实例化   
  20.         btn_ok = (Button) findViewById(R.id.btn_ok);  
  21.         //对btn_cancel对象进行实例化   
  22.         btn_cancel = (Button) findViewById(R.id.btn_cancel);  
  23.         //对tv对象进行实例化   
  24.         tv =(TextView) findViewById(R.id.tv);  
  25.         //将btn_ok按钮绑定在点击监听器上   
  26.         btn_ok.setOnClickListener(this);  
  27.         //将btn_cancel按钮绑定在点击监听器上   
  28.         btn_cancel.setOnClickListener(this);  
  29.     }  
  30.     //使用点击监听器必须重写其抽象函数,   
  31.     public void onClick(View v) {  
  32.         // TODO Auto-generated method stub   
  33.         if(v == btn_ok){  
  34.             tv.setText("确定按钮触发事件!");  
  35.         }else if(v == btn_cancel){  
  36.             tv.setText("取消按钮触发事件!");  
  37.         }     
  38.     }  
  39. }  

更多Android相关信息见Android 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=11

linux
相关资讯       Android游戏开发 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款