WheelView-Luke Deighton

问题描述 投票:0回答:1

这是我第一次在堆栈上,因为大部分问题的答案已经可用,但是这个由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,这个代码大多是从MainActivityWheelViewcode复制粘贴

https://github.com/LukeDeighton/WheelView/blob/master/WheelViewSample/src/main/java/com/lukedeighton/wheelsample/MainActivity.java

但没有运气,你们可以帮助我吗?

android kotlin android-custom-view
1个回答
0
投票

显然,缺少的唯一代码是xml属性,即wheelItemCount,并添加了wheelview项目。

© www.soinside.com 2019 - 2024. All rights reserved.