千磨万击还坚劲,任尔东西南北风。这篇文章主要讲述安卓事件大全相关的知识,希望能为你提供帮助。
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 = https://www.songbingjia.com/android/getResources().openRawResource(R.drawable.a);
Day07.this.setWallpaper(data);
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
});
推荐阅读
- android入门,看这一本书就够了
- Android C语言_init函数和constructor属性及.init/.init_array节探索
- Android,重新出发!
- AutoMapper
- 从国内APP更新“精雕细琢” 看国内外产品理念之差
- Android AAR的tools:replace冲突解决方案(转载)
- 消息推送之百度云推送Android集成与用法
- [转]App离线本地存储方案
- Eclipse+Maven(webapp)+Jetty+JReBel的配置方法