2011-03-28 120 views
0

我正在創建一個自定義適配器,簡單的東西,它是爆炸對公共int getCount()的adpater。我不知道我錯過了什麼?實現自定義適配器

public class GREVocabulary extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 

     // set the color mlayout.setBackgroundColor(Color.WHATEVER); 
     setContentView(R.layout.main); 
     List<String> alphabetslsit = Arrays.asList(getResources().getStringArray(R.array.alphabet));  
     Spinner spinner = (Spinner) findViewById(R.id.spinner); 
     try{ 
     AlphabetAdapter adapter = new AlphabetAdapter(this,alphabetslsit); 


     spinner.setAdapter(adapter); 
     } 
     catch (Exception e) 
     { 
      Log.v(e.toString(),e.getMessage()); 
     } 

    } 
} 

public class AlphabetAdapter extends BaseAdapter implements SpinnerAdapter 
{ 


    private List<String> aplhabetlist; 
    private Context context; 

    public AlphabetAdapter(Context context, List<String> aplhabetlist) { 
     this.context = context; 
     this.aplhabetlist = aplhabetlist; 
    } 

    @Override 
    public int getCount() 
    { 

     return aplhabetlist.size(); 
    } 

    @Override 
    public Object getItem(int arg0) { 
     return aplhabetlist.get(arg0); 
    } 

    @Override 
    public long getItemId(int arg0) { 

     return arg0; 
    } 

    @Override 
    public View getView(int arg0, View arg1, ViewGroup arg2) 
    { 
     View view = super.getDropDownView(arg0, arg1, arg2); 
     //if (arg0 % 2 == 0) 
     //{ 
     // view.setBackgroundColor(Color.BLUE); 
     //} 

     return view; 

    } 

} 

的exeception我得到

// Stack: 2, Locals: 2 
    public bridge synthetic void setAdapter(android.widget.Adapter x0); 
    0 aload_0 [this] 
    1 aload_1 [x0] 
    2 checkcast android.widget.SpinnerAdapter [7] 
    5 invokevirtual android.widget.AbsSpinner.setAdapter(android.widget.SpinnerAdapter) : void [8] 
    8 return 
     Line numbers: 
     [pc: 0, line: 2] 
     Local variable table: 
     [pc: 0, pc: 9] local: this index: 0 type: android.widget.AbsSpinner 
     [pc: 0, pc: 9] local: x0 index: 1 type: android.widget.Adapter 

    // Method descriptor #67()Landroid/widget/Adapter; 
    // Stack: 1, Locals: 1 
    public bridge synthetic android.widget.Adapter getAdapter(); 
    0 aload_0 [this] 
    1 invokevirtual android.widget.AbsSpinner.getAdapter() : android.widget.SpinnerAdapter [9] 
    4 areturn 
     Line numbers: 
     [pc: 0, line: 2] 
     Local variable table: 
     [pc: 0, pc: 5] local: this index: 0 type: android.widget.AbsSpinner 

    Inner classes: 
    [inner class info: #36 android/view/ViewGroup$LayoutParams, outer class info: #83 android/view/ViewGroup 
    inner name: #37 LayoutParams, accessflags: 9 public static] 
+0

爆炸如何?例外?什麼信息? – 2011-03-28 04:52:50

+0

你得到了什麼異常或錯誤? – Vinay 2011-03-28 04:54:44

回答

1

BaseAdapter下已經實現SpinnerAdapter。所以不需要顯式地實現SpinnerAdapter。

HTH!

+0

我也嘗試過,爲了以防萬一。 – Gainster 2011-03-28 05:40:19

+0

您是否看到任何異常? – Karan 2011-03-28 05:41:21

+0

我粘貼的期待 – Gainster 2011-03-28 06:03:53