
大家好,我有一个轮式捡拾器,但目前所有轮式捡拾器的编号都从0-9递增.我希望能够设置值而不是0-9,我希望它是从数组或字符串中提取的单词,因此我可以输入myslef,因为我不确定当前从何处提取数字.代码如下:
public class PasswActivity extends Activity {@OverrIDepublic voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.passw_layout); initWheel(R.ID.passw_1); initWheel(R.ID.passw_2); initWheel(R.ID.passw_3); initWheel(R.ID.passw_4); button mix = (button)findVIEwByID(R.ID.btn_mix); mix.setonClickListener(new OnClickListener() { public voID onClick(VIEw v) { mixWheel(R.ID.passw_1); mixWheel(R.ID.passw_2); mixWheel(R.ID.passw_3); mixWheel(R.ID.passw_4); } });}// Wheel scrolled flagprivate boolean wheelScrolled = false;// Wheel scrolled ListenerOnWheelScrollListener scrolledListener = new OnWheelScrollListener() { public voID onScrollingStarted(WheelVIEw wheel) { wheelScrolled = true; } public voID onScrollingFinished(WheelVIEw wheel) { wheelScrolled = false; }};// Wheel changed Listenerprivate OnWheelChangedListener changedListener = new OnWheelChangedListener() { public voID onChanged(WheelVIEw wheel, int oldValue, int newValue) { if (!wheelScrolled) { } }};/** * Initializes wheel * @param ID the wheel Widget ID */private voID initWheel(int ID) { WheelVIEw wheel = getWheel(ID); wheel.setVIEwAdapter(new NumericWheelAdapter(this, 0, 9)); wheel.setCurrentItem((int)(Math.random() * 10)); wheel.addChangingListener(changedListener); wheel.addScrollingListener(scrolledListener); wheel.setCyclic(true); wheel.setInterpolator(new AnticipateOvershootInterpolator());}/** * 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 entered PIN * @param v1 * @param v2 * @param v3 * @param v4 * @return true */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);}/** * 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 boolean testWheelValue(int ID, int value) { return getWheel(ID).getCurrentItem() == value;}/** * Mixes wheel * @param ID the wheel ID */private voID mixWheel(int ID) { WheelVIEw wheel = getWheel(ID); wheel.scroll(-25 + (int)(Math.random() * 50), 2000);}}任何帮助都适用.谢谢
解决方法:
您能否在下面的车轮演示项目中进行参考,它会极大地帮助您解决车轮中的字符串数据问题.
http://code.google.com/p/android-wheel/
public class CitIEsActivity extends Activity { // Scrolling flag private boolean scrolling = false; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.citIEs_layout); final WheelVIEw country = (WheelVIEw) findVIEwByID(R.ID.country); country.setVisibleItems(3); country.setVIEwAdapter(new CountryAdapter(this)); final String citIEs[][] = new String[][] { new String[] {"New York", "Washington", "Chicago", "Atlanta", "Orlando"}, new String[] {"ottawa", "Vancouver", "Toronto", "Windsor", "Montreal"}, new String[] {"KIEv", "Dnipro", "Lviv", "Kharkiv"}, new String[] {"Paris", "Bordeaux"}, }; final WheelVIEw city = (WheelVIEw) findVIEwByID(R.ID.city); city.setVisibleItems(5); country.addChangingListener(new OnWheelChangedListener() { public voID onChanged(WheelVIEw wheel, int oldValue, int newValue) { if (!scrolling) { updateCitIEs(city, citIEs, newValue); } } }); country.addScrollingListener( new OnWheelScrollListener() { public voID onScrollingStarted(WheelVIEw wheel) { scrolling = true; } public voID onScrollingFinished(WheelVIEw wheel) { scrolling = false; updateCitIEs(city, citIEs, country.getCurrentItem()); } }); country.setCurrentItem(1); } /** * Updates the city wheel */ 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); } /** * Adapter for countrIEs */ private class CountryAdapter extends AbstractWheelTextAdapter { // CountrIEs names private String countrIEs[] = new String[] {"USA", "Canada", "Ukraine", "France"}; // CountrIEs flags private int flags[] = new int[] {R.drawable.usa, R.drawable.canada, R.drawable.ukraine, R.drawable.france}; /** * Constructor */ protected CountryAdapter(Context context) { super(context, R.layout.country_layout, NO_RESOURCE); setItemTextResource(R.ID.country_name); } @OverrIDe public VIEw getItem(int index, VIEw cachedVIEw, VIEwGroup parent) { VIEw vIEw = super.getItem(index, cachedVIEw, parent); ImageVIEw img = (ImageVIEw) vIEw.findVIEwByID(R.ID.flag); img.setimageResource(flags[index]); return vIEw; } @OverrIDe public int getItemsCount() { return countrIEs.length; } @OverrIDe protected CharSequence getItemText(int index) { return countrIEs[index]; } }} 总结 以上是内存溢出为你收集整理的Android Array for Wheel Picker全部内容,希望文章能够帮你解决Android Array for Wheel Picker所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)