Android wheel picker example
Now you can with Android-Wheel WheelPicker for Android:
Download Source Code Here
Android-Wheel:
It comes with a handy ScrollListener for listen to touch events on the wheel component.
source code
package com.vijay;
import com.vijay.wheel.ArrayWheelAdapter;
import com.vijay.wheel.OnWheelChangedListener;
import com.vijay.wheel.OnWheelScrollListener;
import com.vijay.wheel.WheelView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity
{
// TODO: Externalize string-array
String wheelMenu1[] = new String[]{"name 1", "name 2", "name 3", "name 4", "name 5", "name 6","name 7","name 8","name 9"};
String wheelMenu2[] = new String[]{"age 1", "age 2", "age 3"};
String wheelMenu3[] = new String[]{"10", "20","30","40","50","60"};
// Wheel scrolled flag
private boolean wheelScrolled = false;
private TextView text;
private EditText text1;
private EditText text2;
private EditText text3;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initWheel1(R.id.p1);
initWheel2(R.id.p2);
initWheel3(R.id.p3);
text1 = (EditText) this.findViewById(R.id.r1);
text2 = (EditText) this.findViewById(R.id.r2);
text3 = (EditText) this.findViewById(R.id.r3);
text = (TextView) this.findViewById(R.id.result);
}
// Wheel scrolled listener
OnWheelScrollListener scrolledListener = new OnWheelScrollListener()
{
public void onScrollStarts(WheelView wheel)
{
wheelScrolled = true;
}
public void onScrollEnds(WheelView wheel)
{
wheelScrolled = false;
updateStatus();
}
};
// Wheel changed listener
private final OnWheelChangedListener changedListener = new OnWheelChangedListener()
{
public void onChanged(WheelView wheel, int oldValue, int newValue)
{
if (!wheelScrolled)
{
updateStatus();
}
}
};
/**
* Updates entered PIN status
*/
private void updateStatus()
{
text1.setText(wheelMenu1[getWheel(R.id.p1).getCurrentItem()]);
text2.setText(wheelMenu2[getWheel(R.id.p2).getCurrentItem()]);
text3.setText(wheelMenu3[getWheel(R.id.p3).getCurrentItem()]);
text.setText(wheelMenu1[getWheel(R.id.p1).getCurrentItem()] + " - " + wheelMenu2[getWheel(R.id.p2).getCurrentItem()] + " - " + wheelMenu3[getWheel(R.id.p3).getCurrentItem()]);
}
/**
* Initializes wheel
*
* @param id
* the wheel widget Id
*/
private void initWheel1(int id)
{
WheelView wheel = (WheelView) findViewById(id);
wheel.setAdapter(new ArrayWheelAdapter<String>(wheelMenu1));
wheel.setVisibleItems(2);
wheel.setCurrentItem(0);
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
}
private void initWheel2(int id)
{
WheelView wheel = (WheelView) findViewById(id);
wheel.setAdapter(new ArrayWheelAdapter<String>(wheelMenu2));
wheel.setVisibleItems(2);
wheel.setCurrentItem(0);
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
}
private void initWheel3(int id)
{
WheelView wheel = (WheelView) findViewById(id);
wheel.setAdapter(new ArrayWheelAdapter<String>(wheelMenu3));
wheel.setVisibleItems(2);
wheel.setCurrentItem(0);
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
}
/**
* Returns wheel by Id
*
* @param id
* the wheel Id
* @return the wheel with passed Id
*/
private WheelView getWheel(int id)
{
return (WheelView) findViewById(id);
}
/**
* Tests wheel value
*
* @param id
* the wheel Id
* @param value
* the value to test
* @return true if wheel value is equal to passed value
*/
private int getWheelValue(int id)
{
return getWheel(id).getCurrentItem();
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/layout_bg">
<LinearLayout
android:layout_marginTop="24dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.vijay.wheel.WheelView
android:id="@+id/p1"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<com.vijay.wheel.WheelView
android:id="@+id/p2"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<com.vijay.wheel.WheelView
android:id="@+id/p3"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp">
<EditText
android:id="@+id/r1"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_gravity="center_horizontal"
android:textSize="18sp"
android:textColor="#000">
</EditText>
<EditText
android:id="@+id/r2"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_gravity="center_horizontal"
android:textSize="18sp"
android:textColor="#000">
</EditText>
<EditText
android:id="@+id/r3"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_gravity="center_horizontal"
android:textSize="18sp"
android:textColor="#000">
</EditText>
</LinearLayout>
<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_gravity="center_horizontal"
android:textSize="18sp"
android:textColor="#FFF"
android:text="Your choice">
</TextView>
</LinearLayout>
Now you can with Android-Wheel WheelPicker for Android:
Download Source Code Here
Android-Wheel:
It comes with a handy ScrollListener for listen to touch events on the wheel component.
source code
package com.vijay;
import com.vijay.wheel.ArrayWheelAdapter;
import com.vijay.wheel.OnWheelChangedListener;
import com.vijay.wheel.OnWheelScrollListener;
import com.vijay.wheel.WheelView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity
{
// TODO: Externalize string-array
String wheelMenu1[] = new String[]{"name 1", "name 2", "name 3", "name 4", "name 5", "name 6","name 7","name 8","name 9"};
String wheelMenu2[] = new String[]{"age 1", "age 2", "age 3"};
String wheelMenu3[] = new String[]{"10", "20","30","40","50","60"};
// Wheel scrolled flag
private boolean wheelScrolled = false;
private TextView text;
private EditText text1;
private EditText text2;
private EditText text3;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initWheel1(R.id.p1);
initWheel2(R.id.p2);
initWheel3(R.id.p3);
text1 = (EditText) this.findViewById(R.id.r1);
text2 = (EditText) this.findViewById(R.id.r2);
text3 = (EditText) this.findViewById(R.id.r3);
text = (TextView) this.findViewById(R.id.result);
}
// Wheel scrolled listener
OnWheelScrollListener scrolledListener = new OnWheelScrollListener()
{
public void onScrollStarts(WheelView wheel)
{
wheelScrolled = true;
}
public void onScrollEnds(WheelView wheel)
{
wheelScrolled = false;
updateStatus();
}
};
// Wheel changed listener
private final OnWheelChangedListener changedListener = new OnWheelChangedListener()
{
public void onChanged(WheelView wheel, int oldValue, int newValue)
{
if (!wheelScrolled)
{
updateStatus();
}
}
};
/**
* Updates entered PIN status
*/
private void updateStatus()
{
text1.setText(wheelMenu1[getWheel(R.id.p1).getCurrentItem()]);
text2.setText(wheelMenu2[getWheel(R.id.p2).getCurrentItem()]);
text3.setText(wheelMenu3[getWheel(R.id.p3).getCurrentItem()]);
text.setText(wheelMenu1[getWheel(R.id.p1).getCurrentItem()] + " - " + wheelMenu2[getWheel(R.id.p2).getCurrentItem()] + " - " + wheelMenu3[getWheel(R.id.p3).getCurrentItem()]);
}
/**
* Initializes wheel
*
* @param id
* the wheel widget Id
*/
private void initWheel1(int id)
{
WheelView wheel = (WheelView) findViewById(id);
wheel.setAdapter(new ArrayWheelAdapter<String>(wheelMenu1));
wheel.setVisibleItems(2);
wheel.setCurrentItem(0);
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
}
private void initWheel2(int id)
{
WheelView wheel = (WheelView) findViewById(id);
wheel.setAdapter(new ArrayWheelAdapter<String>(wheelMenu2));
wheel.setVisibleItems(2);
wheel.setCurrentItem(0);
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
}
private void initWheel3(int id)
{
WheelView wheel = (WheelView) findViewById(id);
wheel.setAdapter(new ArrayWheelAdapter<String>(wheelMenu3));
wheel.setVisibleItems(2);
wheel.setCurrentItem(0);
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
}
/**
* Returns wheel by Id
*
* @param id
* the wheel Id
* @return the wheel with passed Id
*/
private WheelView getWheel(int id)
{
return (WheelView) findViewById(id);
}
/**
* Tests wheel value
*
* @param id
* the wheel Id
* @param value
* the value to test
* @return true if wheel value is equal to passed value
*/
private int getWheelValue(int id)
{
return getWheel(id).getCurrentItem();
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/layout_bg">
<LinearLayout
android:layout_marginTop="24dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.vijay.wheel.WheelView
android:id="@+id/p1"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<com.vijay.wheel.WheelView
android:id="@+id/p2"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<com.vijay.wheel.WheelView
android:id="@+id/p3"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp">
<EditText
android:id="@+id/r1"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_gravity="center_horizontal"
android:textSize="18sp"
android:textColor="#000">
</EditText>
<EditText
android:id="@+id/r2"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_gravity="center_horizontal"
android:textSize="18sp"
android:textColor="#000">
</EditText>
<EditText
android:id="@+id/r3"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_gravity="center_horizontal"
android:textSize="18sp"
android:textColor="#000">
</EditText>
</LinearLayout>
<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_gravity="center_horizontal"
android:textSize="18sp"
android:textColor="#FFF"
android:text="Your choice">
</TextView>
</LinearLayout>
Looks like a nice widget, a good solution for devices < honeycomb. Possibly you might want to make it more combatible with the standard number picker so that it can just be replaced in resources for devices <3.0.
ReplyDeletecode you please post the full code or send it to my my email , i have been trying to download the code from google code usin svn however it's not working !!
ReplyDeletehttp://www.megaupload.com/?d=SORK7YDK... check this url u can get full source code
ReplyDeleteHi Vijay,
Deletecan u pls send full code to my email as well.
its will realy help me.
tomersadi@gmail.com
Thanks alot for your help and time,
Tomer
Hi, i cannot download the src code from megaupload , because my country is banned by megaupload:(
ReplyDeletecould you mind to upload to other server?
How do I get your project into eclipse to actually use???
ReplyDeleteHow do I get your widget to show up as something I can drag onto the canvas?? I'm lost
What are the steps??
Sorry , im just an extreme nubee ?
Proud of you tamilan :)
ReplyDeleteSuper machi..
Hi....
ReplyDeletecode you please post the full code or send it to my my email..
email : mokdokyun@naver.com
can i disable wheel do scroll ? show display alone??
ReplyDeletee-mail pathomphong@spi.co.th
Thank for answer...
can any one send complete source code of this my email id is ramki429@gmail.com
ReplyDeleteHi ram
Deletesoon i will upload another server
Can you upload this in "mediafire"? It's very fast. Thank you!
Deletehai vijay please send source code of wheelview sruthibn@gmail.com
ReplyDeletesend me source code ...sruthibn@gmail.com
ReplyDeleteplease any one give me the source code ramzi.slimeni@gmail.com
ReplyDeletehi
ReplyDeletecan u send me source code .....to my mail Surya.bondadaa@gmail.com
hai vijay please send source code of wheelview solutino.salu@gmail.com
ReplyDeletecan any one send complete source code of this my email id is only340@naver.com
ReplyDeleteplease answer me
Thanks a lot for the clear example. Your code helped me big time.. thanks!!
ReplyDeleteCan u provide the wheel in horizontal ?
ReplyDelete............
Hi Could You Please send me the full source code to my email mmaidul.islam@gmail.com
ReplyDeleteThanks for your post.Hope in future you would be good asset for android OS.
Thanks a lot.
HI could you please send me the source code to ganesh.rrp@gmail.com.
ReplyDeleteHello Guys..
ReplyDeleteI uploaded different Server Please Check it.
Hello!
ReplyDeletePls send me source code to kovacsp.regens@gmail.com
Super AnnA
ReplyDeletehi m kalai super ah iruku
ReplyDeletesnd me full source code
ReplyDeleteHi, could you send me the full source code to my email: thanhha0409@gmail.com?
ReplyDeleteThank you so much!
Hi Unknown,
ReplyDeleteyou can able to download through that above link.. i hope u can ...
Hi Vijay
ReplyDeleteu did a nice job but m afraid that ur link is broken kindly repair it or email me the source code. It 'll be very great full.
THANX
Regards
Bilal Rabbani
bilalrabbani1@live.com
HI Vijay
ReplyDeletecould you please send me the source code on ankit361@gmail.com
Thank you
Hello Friends,
ReplyDeleteI uploaded source in different server.so now you can able to download.
thanks vijayakumar ur blog is really helpfull..and very nice
ReplyDeletecould you please send me the source code on phoommy@gmail.com
ReplyDeleteTHANK YOU ^^
this code is not working please any one help me send me code on sharmakunal312@gmail.com
ReplyDeletethanks
This comment has been removed by a blog administrator.
ReplyDeletecould you please send me the source code on quangle52pm@gmail.com
ReplyDeleteTHANK YOU ^^
Reply
initWheel1(R.id.p1);
ReplyDeletewhat is intiwheel1??
How to use this code for horizontal wheel picker
ReplyDeletehi
ReplyDeletethis is ashok
can u plz send full source code to my mail plz.
vadluri.ashok@gmail.com
thank you
please any one give me the source code thanarat305@gmail.com
ReplyDelete