How to get selected text using android spinner wheel?

雨燕双飞 提交于 2019-12-08 08:42:49

问题


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>

回答1:


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
        }
    };



回答2:


This is what I found in demo to get value.

value=getWheel(viewId).getCurrentItem();

Method

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

Or

value=wheelHorizontalView1.getCurrentItem();


来源:https://stackoverflow.com/questions/29886579/how-to-get-selected-text-using-android-spinner-wheel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!