Sto cercando di creare un raccoglitore di ruote come this Ho provato a scaricare questo progetto ma gli unici file inclusi nel download .zip sono wheel-demo.apk e notes.txt. Notes.txt non ha istruzioni su come utilizzare questo file con Android Studio. Ho trovato un post che suggeriva di usare ListViews per creare lo stesso effetto. Invece di fare il mio ho passato un altro giorno a cercare su Internet e ho trovato il codice sorgente here ma quando ho importato i file nel mio progetto l'IDE ha mostrato dozzine di errori. Attraverso tentativi ed errori sono riuscito a correggere tutti tranne 3 errori. Abbastanza sicuro ho messo il codice in questione sotto
MainActivity.java:Come fare un raccoglitore di ruote
OnWheelScrollListener scrolledListener = new OnWheelScrollListener()
{
public void onScrollingStarted(WheelView wheel)
{
wheelScrolled = true;// "Cannot resolve symbol wheelScrolled
}
public void onScrollingFinished(WheelView wheel)
{
wheelScrolled = false;// "Cannot resolve symbol wheelScrolled
updateStatus();
}
};
// Wheel changed listener
private final OnWheelChangedListener changedListener = new OnWheelChangedListener()
{
public void onChanged(WheelView wheel, int oldValue, int newValue)
{
if (!wheelScrolled)// "Cannot resolve symbol wheelScrolled
{
updateStatus();
}
}
};
private void initWheel1(int id)
{
WheelView wheel = (WheelView) findViewById(id);
wheel.setAdapter(new ArrayWheelAdapter<String>(wheelMenu1)); //cannot resolve method 'setAdapter(com.projectname.ArrayWheelAdapter<Java.lang.String>)
wheel.setVisibleItems(2);
wheel.setCurrentItem(0);
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
}
OnWheelScrollListener.java:
public interface OnWheelScrollListener {
/**
* Callback method to be invoked when scrolling started.
* @param wheel the wheel view whose state has changed.
*/
void onScrollingStarted(WheelView wheel);
/**
* Callback method to be invoked when scrolling ended.
* @param wheel the wheel view whose state has changed.
*/
void onScrollingFinished(WheelView wheel);}
OnWheelChangedListener.java:
public interface OnWheelChangedListener {
/**
* Callback method to be invoked when current item changed
* @param wheel the wheel view whose state has changed
* @param oldValue the old value of current item
* @param newValue the new value of current item
*/
void onChanged(WheelView wheel, int oldValue, int newValue);
}
ArrayWheelAdapter.java
public class ArrayWheelAdapter<T> extends AbstractWheelTextAdapter {
// items
private T items[];
/**
* Constructor
* @param context the current context
* @param items the items
*/
public ArrayWheelAdapter(Context context, T items[]) {
super(context);
//setEmptyItemResource(TEXT_VIEW_ITEM_RESOURCE);
this.items = items;
}
@Override
public CharSequence getItemText(int index) {
if (index >= 0 && index < items.length) {
T item = items[index];
if (item instanceof CharSequence) {
return (CharSequence) item;
}
return item.toString();
}
return null;
}
@Override
public int getItemsCount() {
return items.length;
}
}
Tutti i 3 file .java sono stati aggiunti all'elenco di importazione in MainActivity pensando che potrebbe risolvere il problema, ma non è stato così. Grazie per il consiglio finora.
Hai provato in quel modo? –
Cosa intendi in questo modo? il codice nel post è per quanto ho ottenuto prima di imbattersi nel problema di scorrimento che ho menzionato. Android Studio non ha potuto importare nulla dai file che ho estratto da .zip che ho scaricato. –
Puoi esportare l'intero progetto su https://code.google.com/p/android-wheel/ su GitHub usando il pulsante "Esporta su GitHub". Ciò semplifica l'importazione in Android Studio. – Kuffs