这是我第一次使用堆栈,因为大多数问题的答案都已经可以找到了,但是Luke Deighton的这个WheelView,我在网上找不到太多关于它的信息,所以它在这里
我要做的是给WheelView设置一个从1到12小时的列表
这是我的片断之一
class SetTimeFragment : android.app.Fragment(), TimePresenter.TimePresenterCallback, WheelView.OnWheelItemSelectListener {
private var hours: List<String>? = null
private var days: List<String>? = null
private var minutes: List<String>? = null
private var type: List<String>? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
var view: View =inflater.inflate(R.layout.fragment_add_time, container, false)
TimePresenter(this).setDataForTimeAndDays()
return view
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setDayslist(days)
setHour(hours)
setMinute(minutes)
setTimeType(type)
}
override fun onDaysOfWeekSuccess(hours: List<String>?, minutes: List<String>?, type: List<String>?, days: List<String>?) {
this.days =days
this.hours =hours
this.minutes =minutes
this.type =type
}
fun setDayslist(days: List<String>?){
rvDays.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false)
rvDays.adapter = DaysInWeekAdapter(days)
}
fun setHour(hours: List<String>?){
// the adapter which I am trying to set
hourWheel.adapter = HoursInDayAdapter(hours)
hourWheel.setSelectionColor(R.color.white)
}
fun setMinute(minutes: List<String>?){
minuteWheel.adapter = MinutesInHourAdapter(minutes)
hourWheel.setSelectionColor(R.color.white)
}
fun setTimeType(type: List<String>?){
typeWheel.adapter = TimeTypeInDayAdapter(type)
hourWheel.setSelectionColor(R.color.white)
}
override fun onWheelItemSelected(parent: WheelView?, itemDrawable: Drawable?, pos: Int) {
}
}
// the adapter set above but in a different class
public class HoursInDayAdapter extends WheelArrayAdapter {
List<String> hours;
public HoursInDayAdapter(List<String> hours) {
super(hours);
this.hours = hours;
}
@Override
public Drawable getDrawable(int position) {
Drawable[] drawable = new Drawable[] {
createOvalDrawable(),
new TextDrawable(hours.get(position))
};
return new LayerDrawable(drawable);
}
private Drawable createOvalDrawable() {
ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
shapeDrawable.getPaint().setColor(Color.BLUE);
return shapeDrawable;
}
@Override
public int getCount() {
return hours.size();
}
}
// the list which I am passing
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]WheelView没有显示任何东西,没有错误,没有任何东西,WheelView出现了,但轮子上什么也没有,我也试过使用一个简单的WheelAdapter,这段代码主要是从WheelView的MainActivity代码复制粘贴过来的
但是不走运,你们能帮我吗?
发布于 2018-06-01 16:57:01
显然,唯一缺少的代码是一个名为wheelItemCount,的xml属性,该属性添加了轮视图项的渲染。
https://stackoverflow.com/questions/50216805
复制相似问题