Introduction:
Usage:
2) DateActivity :
http://code.google.com/p/android-wheel/
- You can use wheel widget for country,state,date,time selection.you can use this wheel control in your project. You have to include WheelLibrary as a library for run this project.
Usage:
- In this project there are six main class.
final WheelView country = (WheelView) findViewById(R.id.country);
country.setVisibleItems(3);
country.setViewAdapter(new CountryAdapter(this));
- Here we use another wheelview for city.When we change and scroll country wheel than updateCities(city, cities, newValue) function will be called in which cities will be list out on the base of selected country.
country.addChangingListener(new OnWheelChangedListener() {
public void onChanged(WheelView wheel, int oldValue, int newValue) {
if (!scrolling) {
updateCities(city, cities, newValue);
}
}
});
country.addScrollingListener( new OnWheelScrollListener() {Updates the city wheel
public void onScrollingStarted(WheelView wheel) {
scrolling = true;
}
public void onScrollingFinished(WheelView wheel) {
scrolling = false;
updateCities(city, cities, country.getCurrentItem());
}
});
private void updateCities(WheelView city, String cities[][], int index) {
ArrayWheelAdapter<String> adapter =
new ArrayWheelAdapter<String>(this, cities[index]);
adapter.setTextSize(18);
city.setViewAdapter(adapter);
city.setCurrentItem(cities[index].length / 2);
}
2) DateActivity :
- In this activity we use three wheelview for day,year and month.
final WheelView month = (WheelView) findViewById(R.id.month);
final WheelView year = (WheelView) findViewById(R.id.year);
final WheelView day = (WheelView) findViewById(R.id.day);
- we use DateArrayAdapter for month and DateNumericAdapter for year and day.When we change and scroll wheelview than OnWheelChangedListener() will be called in which we specify updateDays(year, month, day) .this function set max days according to selected month and year.
3) PasswActivity:
void updateDays(WheelView year, WheelView month, WheelView day) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + year.getCurrentItem());
calendar.set(Calendar.MONTH, month.getCurrentItem());
int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
day.setViewAdapter(new DateNumericAdapter(this, 1, maxDays, calendar.get(Calendar.DAY_OF_MONTH) - 1));
int curDay = Math.min(maxDays, day.getCurrentItem() + 1);
day.setCurrentItem(curDay - 1, true);
}
- When we change and scroll wheelview than OnWheelChangedListener() will be called in which we specify updateStatus().this function check whichever number selected is true or not.
private void updateStatus() {4) SlotMachineActivity:
TextView text = (TextView) findViewById(R.id.pwd_status);
if (testPin(2, 4, 6, 1)) {
text.setText("Congratulation!");
} else {
text.setText("Invalid PIN");
}
} private boolean testPin(int v1, int v2, int v3, int v4) {
return testWheelValue(R.id.passw_1, v1) && testWheelValue(R.id.passw_2, v2) &&
testWheelValue(R.id.passw_3, v3) && testWheelValue(R.id.passw_4, v4);
}
- This activity do same functionality like PasswActivity done.
- This activity do same functionality like DateActivity done.Additional code is for time selection.
- This activity do same functionality like Time2Activity but here we just select time.we can not select date.
http://code.google.com/p/android-wheel/







0 comments :
Post a Comment