Android 如何设置wheelView项目

Android 如何设置wheelView项目,android,custom-view,Android,Custom View,我在Github中找到了这个项目,但我无法实现如何在wheelView中的不同位置设置不同的项目。我想添加两项(ArrayList列表) 谁能拦住我 这是我的代码: public class MainActivity extends AppCompatActivity { private WheelView wheelView; private ArrayList<Drawable> list; @Override protected void onCreate(Bundle s

我在Github中找到了这个项目,但我无法实现如何在wheelView中的不同位置设置不同的项目。我想添加两项(ArrayList列表) 谁能拦住我

这是我的代码:

public class MainActivity extends AppCompatActivity {

private WheelView wheelView;
private ArrayList<Drawable> list;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //This is the items I want to add
    list = new ArrayList<>();
    list.add(getResources().getDrawable(R.drawable.loader));
    list.add(getResources().getDrawable(R.drawable.twitter));
    ////

    wheelView = (WheelView) findViewById(R.id.wheelView);

    wheelView.setAdapter(new WheelAdapter() {

        @Override
        public Drawable getDrawable(int position) {

            return ...;
        }

        @Override
        public int getCount() {
            return (int)wheelView.getItemCount();
        }

        @Override
        public Object getItem(int position) {
            return 0;
        }
    });

}
}
public类MainActivity扩展了AppCompatActivity{
私家车;
私有数组列表;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//这是我要添加的项目
列表=新的ArrayList();
add(getResources().getDrawable(R.drawable.loader));
add(getResources().getDrawable(R.drawable.twitter));
////
wheelView=(wheelView)findViewById(R.id.wheelView);
wheelView.setAdapter(新的WheelAdapter(){
@凌驾
公共可提取getDrawable(内部位置){
回来
}
@凌驾
public int getCount(){
return(int)wheelView.getItemCount();
}
@凌驾
公共对象getItem(int位置){
返回0;
}
});
}
}
这是xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.roashviz.giftest2.MainActivity">



<com.lukedeighton.wheelview.WheelView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/wheelView"
    app:wheelColor="@color/colorAccent"
    app:rotatableWheelDrawable="true"
    app:selectionAngle="270.0"
    app:wheelPosition=""
    app:wheelOffsetY="0dp"
    app:repeatItems="true"
    app:wheelRadius="150dp"
    app:wheelItemCount="2"
    app:wheelPadding="13dp"
    app:wheelItemRadius="43dp"
    android:layout_alignParentBottom="true" />


谢谢!!:)

我想你需要像这样更新你的代码,我没有尝试过,但它应该可以工作

wheelView.setAdapter(new WheelAdapter() {

@Override
public Drawable getDrawable(int position) {

    return list.get(position);
}

@Override
public int getCount() {
    return list.size();
}

@Override
public Object getItem(int position) {
    return list.get(position);
}
});

我想你需要像这样更新你的代码,我没有尝试过,但它应该可以工作

wheelView.setAdapter(new WheelAdapter() {

@Override
public Drawable getDrawable(int position) {

    return list.get(position);
}

@Override
public int getCount() {
    return list.size();
}

@Override
public Object getItem(int position) {
    return list.get(position);
}
});

要启动并运行此功能,最简单的方法是查看与您尝试使用的库关联的示例项目:

您还可以通过浏览其他文件找到有用的信息:

您甚至可以下载整个程序,并在使用库之前亲自尝试,以确保它至少能正常工作


我希望这能让你知道你需要做什么

启动并运行该库的最简单方法是查看与您尝试使用的库相关联的示例项目:

您还可以通过浏览其他文件找到有用的信息:

您甚至可以下载整个程序,并在使用库之前亲自尝试,以确保它至少能正常工作


我希望这能让你知道你需要做什么

您是指WheelView适配器$getDrawable中所需的代码?您是指WheelView适配器$getDrawable中所需的代码?如何将自定义视图与此一起使用?如何将自定义视图与此一起使用?