ImageVerifierCode 换一换
格式:DOCX , 页数:13 ,大小:19.11KB ,
资源ID:3006547      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3006547.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Android界面事件响应.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Android界面事件响应.docx

1、Android界面事件响应1.Button事件响应protected void onCreate(Bundle savedInstanceState)super.onCreate(savedInstanceState); /继承父类的onCreate()方法setContentView(R.layout.activity_main); /指定使用用户的UI界面文件为activity_main.xmlButton btn=(Button)findViewById(R.id.button1); /通过findViewById方法获得Button1的对象btn.setOnClickListener(

2、new OnClickListener() /使用OnClickListener接口作为监听器,新建并实现匿名类public void onClick(View v)setTitle(设置标题); Log.i(Main_Activity,设置LogCat中打印的字符); /黄色部分为活动名,红色部分设置输出内容TextView text=(TextView)findViewById(R.id.textview1);text.setText(设置输出文字); /输出文字到texttext.setTextColor(Color.RED); /设置显示字体的颜色text.setTextSize(Ty

3、pedValue.COMPLEX_MANTISSA_MASK,20); /设置显示字体大小text.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD); /设置显示字体的风格Intent intent=new Intent(MainActivity.this,NewActivity.class);startActivity(intent); /启动新的Activity /onClick方法结束); /实现匿名类 /onCreate方法结束/*使用Button打开新Activity引用import android.os.Bundle;impo

4、rt android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;*/2.EditText事件响应protected void onCreate(Bundle savedInstanceState)super.onCreate(savedInstanceState);setContentView(R.layout.n

5、ew_activity);TextView tv=(TextView)findViewById(R.id.textview1);EditText et=(EditText)findViewById(R.id.editText1);et.addTextChangedListener(new TextWatcher() /watcherwt(r)n观察者public void afterTextChanged(Editable s) /editabledtbladj可编辑的/*this method is called to notify you that ,somewhere within s,

6、the text has been changed调用此方法来通知你,文本在某个地方已经更改*/public void beforeTextChanged(CharSequence s,int start,int count,int after) /sequencesikw()nsn顺序/*this method is called to notify you that,within s,the count characters beginning at start are about to be replace by new text with length afte调用此方法来通知你,在字

7、符顺序、字符计数开始即将取代后通过新的文本长度*/public void onTextChanged(CharSequence s,int start,int before,int count)/*this method is called to notify you that,within s,the count characters beginning at start have just replaced old text that had length before调用此方法来通知你,在字符顺序、字符计数开始之前就取代了旧的文本长度*/String text=et.getText().

8、toString();tv.setText(text););3.CheckBox事件响应public class CheckBoxActivity extends Activityprivate TextView tv;private CheckBox book,song,football;protected void onCreate(Bundle savedInstanceState)super.onCreate(savedInstanceState);setContentView(R.layout.checkbox);tv=(TextView)findViewById(R.id.text

9、view1);book=(CheckBox)findViewById(checkbox1);song=(CheckBox)findViewById(checkbox2);football=(CheckBox)findViewById(checkbox3);book.setOnCheckedChangeListener(new CompundButton.OnCheckedChangeListener() /*匿名类CompundButton使用了OnCheckedChangeListener()接口CompundButton.OnCheckedChangeListener一个带有选中/未选中状

10、态的按钮。当按钮按下或点中时自动改变状态*/public void onCheckedChanged(CompundButton buttonView,bollean isChecked) /*public abstract void onCheckedChanged在按钮选中状态发生改变时被调用*/if(book.isChecked()tv.append(book.getText().toString();elseif(tv.getText().toString().contains(看书); /*public boolean contains(CharSequence s)判断指定字符串是

11、否包含指定字符序列,如果包含返回true,否则返回false .for example:String s=this is my first java application;boolean a=str.contains(java);*/ tv.setText(tv.getText().toString().replace(看书,);/*public String replace(Char oldChar,char newChar)方法将字符串str中的字符串A替换成字符串B。for example:String s=book;s=s.replace(book,reading);*/ /if语句

12、结束 /else语句结束 /onCheckedChanged方法结束); /匿名类CompundButton.OnCheckedChangeListener结束song.setOnCheckedChangeListener(new CompundButton.OnCheckedChangeListener()public void onCheckedChanged(CompundButton buttonView,boolean isChecked). .); /对所有组件一一监听4.单项选择按钮组(RadioGroup)public class MainActivity extends Ac

13、tivity RadioGroup group; /*group是类MainActivity的成员,在MainActivity中可以被调用。匿名类RadioGroup的方法只能使用RadioGroup的成员,故TextView、RadioButton的对象应该在RadioGroup中定义*/Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); group=(RadioGroup)f

14、indViewById(R.id.radioGroup1); group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() /*匿名类RadioGroup使用了OnCheckedChangeListener接口*/TextView hint=(TextView)findViewById(R.id.textView1); RadioButton first=(RadioButton)findViewById(R.id.radio0); RadioButton second=(RadioButton)findVi

15、ewById(R.id.radio1); RadioButton third=(RadioButton)findViewById(R.id.radio2); public void onCheckedChanged(RadioGroup group,int checkedId) String groupText=实例:; if(checkedId= =first.getId()/*使用if.else if方法查看用户点击的是哪一个按钮。这里用到两个方法:getId()返回按钮的Id值;getText()返回按钮上的字符串;*/ groupText+=first.getText().toString(); hint.setText

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1