码迷,mamicode.com
首页 > 移动开发 > 详细

安卓事件大全

时间:2017-05-25 13:26:24      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:hang   int   button   cep   ssi   nbsp   als   boolean   return   

1 OnClickListener(单击事件)
组件.setOnClickListener(new OnClickListener() {
  public void onClick(View v) {
    String str = et.getText().toString();
    tv.setText(str);
  }
});

2 OnCheckedChangeListener(单选发生变化)
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  public void onCheckedChanged(
    RadioGroup group, int checkedId) {
    RadioButton rb = (RadioButton)
    findViewById(checkedId);
    String str = rb.getText().toString();
    tv.setText(str);
  }
});


3 OnItemSelectedListener(下拉列表)
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
  public void onItemSelected(AdapterView<?> arg0, View view,
  int arg2, long arg3) {
  TextView tv1 = (TextView) view;
  String str = tv1.getText().toString();
  tv.setText(str);
  }

public void onNothingSelected(AdapterView<?> arg0) {
}
}); 

4 OnTimeChangedListener 时间事件监听

5 OnFocusChangeListener 焦点事件
et.setOnFocusChangeListener(new OnFocusChangeListener() {
  public void onFocusChange(View v, boolean hasFocus) {
    if(hasFocus){
    et.setText("");
    }else{
    String str= et.getText().toString();
    tv.setText(str);
  }
}
});


6 OnDateChangeListener
dp.init(2017, 4, 23, new OnDateChangedListener() {
public void onDateChanged(DatePicker view, int year, int monthOfYear,
  int dayOfMonth) {
    tv.setText(year+"-"+monthOfYear+"-"+dayOfMonth);
  }
});

7 OnLongChangeListener(长按事件)
  <!-- 设置修改桌面背景权限 -->
<uses-permission android:name="android.permission.SET_WALLPAPER" />
iv.setOnLongClickListener(new OnLongClickListener() {
  public boolean onLongClick(View v) {
    try {
      Day07.this.clearWallpaper();
      //getResources();//获得资源对象
    InputStream data = getResources().openRawResource(R.drawable.a);
    Day07.this.setWallpaper(data);
    } catch (IOException e) {
      e.printStackTrace();
    }
     return false;
  }
});

安卓事件大全

标签:hang   int   button   cep   ssi   nbsp   als   boolean   return   

原文地址:http://www.cnblogs.com/yangchan250/p/6902809.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!