这是我第一次在筹码上,因为大多数问题的答案已经可用,但是Luke Deighton的WheelView
,我在网上找不到它,所以这里是
我要做的是设置从1到12到WheelView
的小时列表
这是我的一个片段
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
,此代码为主要通过仅MainActivity
WheelView
代码复制粘贴
但没有运气,你们可以帮助我吗
答案 0 :(得分:0)
显然,缺少的唯一代码是xml属性,即 wheelItemCount ,并补充说已经渲染了wheelview项目。