1

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:

spinner wheel image

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>
Machavity
  • 30,841
  • 27
  • 92
  • 100
Axay Prajapati
  • 791
  • 5
  • 20
  • Are you trying to find out which item is selected? Because you say "how to get 3 as my selected text ?", but 3 is already selected, so I'm thinking what you mean is "how do I determine what is selected?" – DWright Apr 27 '15 at 03:33
  • look like want to get selected text as question says "How to get selected text ...." – Bharatesh Apr 27 '15 at 04:18
  • Yes, I want to get text of selected text, whatever field comes in green square after scrolling. – Axay Prajapati Apr 27 '15 at 04:31
  • How did you set a green background on the selected item? – W.K.S Dec 29 '15 at 11:11

2 Answers2

2

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
        }
    };
Christian Abella
  • 5,747
  • 2
  • 30
  • 42
  • How do I get index, after whatever codes written above in my question? and if it says setCurrentItem(index) where do it calls to getCurrentItem(). – Axay Prajapati Apr 27 '15 at 04:34
  • more here: https://github.com/ai212983/android-spinnerwheel/blob/master/demo/src/antistatic/spinnerwheel/demo/ProgrammaticSwitchingActivity.java – Christian Abella Apr 27 '15 at 04:47
1

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();
Bharatesh
  • 8,943
  • 3
  • 38
  • 67
  • Any Particular Listener is there in which, I can call Toast.makeText(this, wheelHorizontalView.getCurrentItem()+1 + "", Toast.LENGTH_SHORT).show(); Because it calls only once, on create. I want it dynamic. – Axay Prajapati Apr 27 '15 at 04:37