简体   繁体   中英

How to get selected text using android spinner wheel?

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM