请教一个关于android wheel的问题,求高手

 我来答
huanglenzhi
2014-12-26 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
采纳数:117538 获赞数:517196
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。

向TA提问 私信TA
展开全部
Activity代码:::package com.winjing.meetingcontroller.ui;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

import kankan.wheel.R;
import kankan.wheel.widget.WheelView;
import kankan.wheel.widget.adapters.AbstractWheelTextAdapter;
import kankan.wheel.widget.adapters.NumericWheelAdapter;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CreatNewMeetingActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_creat_new_meeting);

Calendar cal = Calendar.getInstance(Locale.CHINA);
final WheelView wheel_hour = (WheelView) findViewById(R.id.hour);
NumericWheelAdapter adapter_hour = new NumericWheelAdapter(this, 0, 23,
"%02d");
adapter_hour.setItemResource(R.layout.wheel_text_item);
adapter_hour.setItemTextResource(R.id.text);
wheel_hour.setViewAdapter(adapter_hour);
// 循环滚动
wheel_hour.setCyclic(true);

final WheelView wheel_minute = (WheelView) findViewById(R.id.minute);
NumericWheelAdapter adapter_minute = new NumericWheelAdapter(this, 0,
59, "%02d");
adapter_minute.setItemResource(R.layout.wheel_text_item);
adapter_minute.setItemTextResource(R.id.text);
wheel_minute.setViewAdapter(adapter_minute);
wheel_minute.setCyclic(true);

// ////////////////////////////

final WheelView wheel_meeting_hour = (WheelView) findViewById(R.id.meeting_hour);
NumericWheelAdapter adapter_meeting_hour = new NumericWheelAdapter(
this, 0, 23, "%02d");
adapter_meeting_hour.setItemResource(R.layout.wheel_text_item);
adapter_meeting_hour.setItemTextResource(R.id.text);
wheel_meeting_hour.setViewAdapter(adapter_meeting_hour);
wheel_meeting_hour.setCyclic(true);

final WheelView wheel_meeting_minute = (WheelView) findViewById(R.id.meeting_minute);
NumericWheelAdapter adapter_meeting_minute = new NumericWheelAdapter(
this, 0, 59, "%02d");
adapter_meeting_minute.setItemResource(R.layout.wheel_text_item);
adapter_meeting_minute.setItemTextResource(R.id.text);
wheel_meeting_minute.setViewAdapter(adapter_meeting_minute);
wheel_meeting_minute.setCyclic(true);

// ////////////////////////////////
Calendar calendar = Calendar.getInstance(Locale.CHINA);
wheel_hour.setCurrentItem(calendar.get(Calendar.HOUR));
wheel_minute.setCurrentItem(calendar.get(Calendar.MINUTE));

final WheelView wheel_day = (WheelView) findViewById(R.id.day);
wheel_day.setViewAdapter(new DayAdapter(this, calendar));
// wheel_day.setCurrentItem(calendar.get(Calendar.DAY_OF_YEAR), false);
wheel_day.setCyclic(true);

}

private class DayAdapter extends AbstractWheelTextAdapter {

// 向下的天数
private final int daysCount = 20;
private Calendar calendar;

/**
* Constructor
*/
protected DayAdapter(Context context, Calendar calendar) {
super(context, R.layout.time2_day, NO_RESOURCE);
this.calendar = calendar;

setItemTextResource(R.id.time2_monthday);
}

@Override
public View getItem(int index, View cachedView, ViewGroup parent) {
// int day = -daysCount / 2 + index;
int day = -daysCount / 2 + index;
int sum = day + index;
Log.v("getItem", "day = " + day + "; index = " + index
+ "; day + index = " + (day + index));
Calendar newCalendar = (Calendar) calendar.clone();

newCalendar.roll(Calendar.DAY_OF_YEAR, day);

View view = super.getItem(index, cachedView, parent);

if (day == 0) {

TextView weekday = (TextView) view
.findViewById(R.id.time2_weekday);
weekday.setText("");

TextView monthday = (TextView) view
.findViewById(R.id.time2_monthday);
monthday.setText("今天");
monthday.setTextColor(0xFF0000F0);
} else {
if (day > 0) {
TextView weekday = (TextView) view
.findViewById(R.id.time2_weekday);
DateFormat format_week = new SimpleDateFormat("EEE");
weekday.setText(format_week.format(newCalendar.getTime()));

TextView monthday = (TextView) view
.findViewById(R.id.time2_monthday);
DateFormat format_month = new SimpleDateFormat("MMM d");
monthday.setText(format_month.format(newCalendar.getTime()));
monthday.setTextColor(0xFF111111);
} else {

TextView weekday_move = (TextView) view
.findViewById(R.id.time2_weekday);
weekday_move.setText("##");
}

}
return view;
}

@Override
public int getItemsCount() {
return daysCount + 1;
}

@Override
protected CharSequence getItemText(int index) {
return "";
}
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友455f0f8
2014-12-26 · TA获得超过142个赞
知道小有建树答主
回答量:174
采纳率:0%
帮助的人:97.5万
展开全部
问题呢??
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式