如何采用了android微调轮得到选中的文本? [英] How to get selected text using android spinner wheel?

查看:209
本文介绍了如何采用了android微调轮得到选中的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Andr​​oid微调轮我已经设置code表示。

  AbstractWheel wheelHorizo​​ntalView1 =(AbstractWheel)findViewById(R.id.wheelHorizo​​ntalView1);
NumericWheelAdapter minAdapter =新NumericWheelAdapter(这一点,1,15,%01D);
minAdapter.setItemResource(R.layout.wheel_text_centered_dark_back);
minAdapter.setItemTextResource(R.id.text);
wheelHorizo​​ntalView1.setViewAdapter(minAdapter);

下面是它的样子:

所以,我的问题是如何让3作为我选中的文本?

下面是XML如果需要的话,

 < RelativeLayout的
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_marginLeft =20dp
    机器人:layout_marginRight =20dp
    机器人:layout_marginTop =20dp>    <查看
        机器人:layout_width =40dp
        机器人:layout_height =40dp
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_marginTop =65dp
        机器人:背景=#007704/>    < com.spinnerwheel.WheelHorizo​​ntalView
        机器人:ID =@ + ID / wheelHorizo​​ntalView1
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_marginTop =60dp
        应用:selectionDivider =@机器人:彩色/白
        应用:selectionDividerWidth =2DP
        应用:visibleItems =6/>
< / RelativeLayout的>


解决方案

您应该叫 setCurrentItem(INT指数)功能:

  wheelHorizo​​ntalView1.setCurrentItem(2);

如果你想知道,当用户更改了该值
你必须实现这个监听器。

  wheelHorizo​​ntalView1.addChangingListener(changedListener);
    ...
    ...
    //轮改为监听器
    私人OnWheelChangedListener changedListener =新OnWheelChangedListener(){
        公共无效调用onChanged(AbstractWheel轮,INT属性oldValue,INT newValue)以{
            // newValue为当前选择的项目
        }
    };

I am using Android Spinner Wheel and I already set code for that.

AbstractWheel wheelHorizontalView1 = (AbstractWheel) findViewById(R.id.wheelHorizontalView1);
NumericWheelAdapter minAdapter = new NumericWheelAdapter(this, 1, 15,"%01d");
minAdapter.setItemResource(R.layout.wheel_text_centered_dark_back);
minAdapter.setItemTextResource(R.id.text);
wheelHorizontalView1.setViewAdapter(minAdapter);

Here is how it looks like:

So, my question is how to get 3 as my selected text ?

Here is xml if needed,

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="20dp">

    <View
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="65dp"
        android:background="#007704" />

    <com.spinnerwheel.WheelHorizontalView
        android:id="@+id/wheelHorizontalView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="60dp"
        app:selectionDivider="@android:color/white"
        app:selectionDividerWidth="2dp"
        app:visibleItems="6" />
</RelativeLayout>

解决方案

You should call setCurrentItem(int index) function:

wheelHorizontalView1.setCurrentItem(2);

If you want to know when the user changed the value you have to implement this listener.

    wheelHorizontalView1.addChangingListener(changedListener);
    ...
    ...  
    // Wheel changed listener
    private OnWheelChangedListener changedListener = new OnWheelChangedListener() {
        public void onChanged(AbstractWheel wheel, int oldValue, int newValue) {
            // newValue is the currently selected item
        }
    };

这篇关于如何采用了android微调轮得到选中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆