Android原生模块DeskClock分析1(4)
DeskClock分析文档
用到了newView和bindView,通过前面的介绍,我们知道这两个方法的功能是:当列表排满时,第一次调用newView,之后只调用bindView就可以了。 private class AlarmTimeAdapter extends CursorAdapter {
public AlarmTimeAdapter(Context context, Cursor cursor) { super(context, cursor); Log.i(\ }
public View newView(Context context, Cursor cursor, ViewGroup parent) { View ret = mFactory.inflate(R.layout.alarm_time, parent, false);
DigitalClock digitalClock =
(DigitalClock) ret.findViewById(R.id.digitalClock); digitalClock.setLive(false); Log.i(\ return ret; }
public void bindView(View view, Context context, Cursor cursor) { Log.i(\
final Alarm alarm = new Alarm(cursor);
View indicator = view.findViewById(R.id.indicator);
// Set the initial resource for the bar image. final ImageView barOnOff =
(ImageView) indicator.findViewById(R.id.bar_onoff); barOnOff.setImageResource(alarm.enabled ?
R.drawable.ic_indicator_on : R.drawable.ic_indicator_off);
// Set the initial state of the clock \ final CheckBox clockOnOff =
(CheckBox) indicator.findViewById(R.id.clock_onoff); clockOnOff.setChecked(alarm.enabled);
// Clicking outside the \ indicator.setOnClickListener(new OnClickListener() { public void onClick(View v) { clockOnOff.toggle();
updateIndicatorAndAlarm(clockOnOff.isChecked(), barOnOff, alarm); Log.i(\ } });
11
DeskClock分析文档
DigitalClock digitalClock =
(DigitalClock) view.findViewById(R.id.digitalClock);
// set the alarm text
final Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, alarm.hour); c.set(Calendar.MINUTE, alarm.minutes); digitalClock.updateTime(c);
digitalClock.setTypeface(Typeface.DEFAULT);
// Set the repeat text or leave it blank if it does not repeat. TextView daysOfWeekView =
(TextView) digitalClock.findViewById(R.id.daysOfWeek); final String daysOfWeekStr =
alarm.daysOfWeek.toString(AlarmClock.this, false); if (daysOfWeekStr != null && daysOfWeekStr.length() != 0) { Log.i(\
daysOfWeekView.setText(daysOfWeekStr); daysOfWeekView.setVisibility(View.VISIBLE); } else {
Log.i(\
daysOfWeekView.setVisibility(View.GONE); }
// Display the label TextView labelView =
(TextView) view.findViewById(R.id.label); if (alarm.label != null && alarm.label.length() != 0) { Log.i(\
labelView.setText(alarm.label); labelView.setVisibility(View.VISIBLE); } else {Log.i(\
labelView.setVisibility(View.GONE); } } };
· 通过onCreateContextMenu方法,长按选中的闹钟,会显示对闹钟操作的选项 @Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { // Inflate the menu from xml.
getMenuInflater().inflate(R.menu.context_menu, menu);
12
DeskClock分析文档
// Use the current item to create a custom view for the header.
final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; final Cursor c =
(Cursor) mAlarmsList.getAdapter().getItem((int) info.position); final Alarm alarm = new Alarm(c);
// Construct the Calendar to compute the time. final Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, alarm.hour); cal.set(Calendar.MINUTE, alarm.minutes); final String time = Alarms.formatTime(this, cal);
// Inflate the custom view and set each TextView's text.
final View v = mFactory.inflate(R.layout.context_menu_header, null); TextView textView = (TextView) v.findViewById(R.id.header_time); textView.setText(time);
textView = (TextView) v.findViewById(R.id.header_label); textView.setText(alarm.label);
// Set the custom view on the menu. menu.setHeaderView(v); Log.i(\
// Change the text based on the state of the alarm. if (alarm.enabled) {Log.i(\
menu.findItem(R.id.enable_alarm).setTitle(R.string.disable_alarm); }
}
· 当点击menu时,通过重写onOptionsItemSelected,弹出菜单选项 @Override
public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) {
case R.id.menu_item_settings:Log.i(\ startActivity(new Intent(this, SettingsActivity.class)); return true;
case R.id.menu_item_desk_clock:Log.i(\ startActivity(new Intent(this, DeskClock.class)); return true;
case R.id.menu_item_add_alarm:Log.i(\ addNewAlarm(); return true;
default:Log.i(\ break;
13
DeskClock分析文档
相关推荐:
- [实用模板]第八章:法国“新浪潮”与“左岸派”
- [实用模板]2021年北京上半年临床医学检验技师生物
- [实用模板]SAP GUI 7.10客户端安装配置文档
- [实用模板]2001年临床执业医师资格考试综合笔试试
- [实用模板]36机场工作实用英语词汇总结
- [实用模板](一)社会保险稽核通知书
- [实用模板]安全教育主题班会材料
- [实用模板]濉溪县春季呼吸道传染病防控应急演练方
- [实用模板]长沙房地产市场周报(1.30-2.3)
- [实用模板]六年级数学上册典中点 - 图文
- [实用模板]C程序设计(红皮书)习题官方参考答案
- [实用模板]中国证监会第一届创业板发行审核委员会
- [实用模板]桥梁工程复习题
- [实用模板]2011学而思数学及答案
- [实用模板]初中病句修改专项练习
- [实用模板]监理学习知识1 - 图文
- [实用模板]小机灵杯四年级试题
- [实用模板]国贸专业毕业论文模板
- [实用模板]教育学概论考试练习题-判断题4
- [实用模板]2015届高考英语一轮复习精品资料(译林
- 00Nkmhe_市场营销学工商管理_电子商务_
- 事业单位考试法律常识
- 诚信教育实施方案
- 吉大小天鹅食品安全检测箱方案(高中低
- 房地产销售培训资料
- 高一地理必修1复习提纲
- 新概念英语第二册lesson_1_练习题
- 证券公司内部培训资料
- 小学英语时间介词专项练习
- 新世纪英语专业综合教程(第二版)第1册U
- 【新课标】浙教版最新2018年八年级数学
- 工程建设管理纲要
- 外研版 必修一Module 4 A Social Surve
- Adobe认证考试 AE复习资料
- 基于H.264AVC与AVS标准的帧内预测技术
- 《食品检验机构资质认定管理办法》(质
- ABB变频器培训课件
- (完整版)小学说明文阅读练习题及答案
- 深思洛克(SenseLock) 深思IV,深思4,深
- 弟子规全文带拼音




