Android 轮阵列半工作

标签 android arrays string android-wheel

我有一个四轮选择器,每个轮子都有字我现在的问题是每个轮子都拉着相同的字你可以看到下面的代码。

我的问题是有人可以帮助我为每个轮子提供自己的单词数组。在下面的 XML 中,您可以看到每个轮子都有自己的 ID,但我不知道如何在 Java 中使用它们,因此每个轮子都有自己的特定数组。

private void initWheel(int id) {
WheelView wheel = getWheel(id);
wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, new String[]{"Abc", "Foo", "Bar"}));
wheel.setCurrentItem((int)(Math.random() * 10));
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
wheel.setCyclic(true);
wheel.setInterpolator(new AnticipateOvershootInterpolator());
}


 private WheelView getWheel(int id) {
 return (WheelView) findViewById(id);
}

我的 XML 是

        <kankan.wheel.widget.WheelView
        android:id="@+id/passw_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

        <kankan.wheel.widget.WheelView
        android:id="@+id/passw_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

       <kankan.wheel.widget.WheelView
        android:id="@+id/passw_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

       <kankan.wheel.widget.WheelView
        android:id="@+id/passw_4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

最佳答案

为每个 WheelView 实例使用不同的 ArrayWheelAdapter 实例。这样您就可以自定义显示在每个 WheelView 中的列表。

<更新>

关键是这一行:

wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, new String[]{"Abc", "Foo", "Bar"}));

您可以在此处指定将出现在每个 WheelView 中的项目。您正在为 WheelView 的每个实例创建一个新的 ArrayWheelAdapter 实例,但它们都包含同一组字符串值 - 这些就是您的 中出现的内容WheelView 控件。

也许你应该尝试这样的事情:

private void initWheel(int id, String[] values) {
WheelView wheel = getWheel(id);
wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, values));
wheel.setCurrentItem((int)(Math.random() * 10));
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
wheel.setCyclic(true);
wheel.setInterpolator(new AnticipateOvershootInterpolator());
}

然后向 initWheel 提供不同的值:

initWheel( R.id.passw_1, new String[] { "Abc", "Foo" } );
initWheel( R.id.passw_2, new String[] { "Def", "Bar" } );

关于Android 轮阵列半工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8182383/

相关文章:

java - 如何将 xmlpullparser 解析的数据传递给另一个类?

java - Android数据存储用于绘制图表

android - org.opencv可以导入,但是不能org.opencv.android吗?

C# List<double> 大小与 double[] 大小

c++ - 为什么表达式的结果取决于表达式的放置位置?

android - 禁用自动滑动。库android-menudrawer

php - 插入数据库后获取所有 url GET 值和一些随机值

c# - 数组的前向和后向搜索算法

python - 选择性 python 字符串替换

c++ - 字符串不通过构造函数参数