2010-02-25 43 views
1

我有一個自定義適配器爲arraylist。Android自定義適配器與酒吧進度

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

<ProgressBar android:id="@+id/downloadprogress" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="200dip" 
    android:layout_height="wrap_content" 
    android:max="100" 
    android:progress="50" 
    android:secondaryProgress="75" /> 
<TextView android:id="@+id/tripsname" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 


</LinearLayout> 

,但是當我嘗試訪問該進度條在適配器

private class MyAdapter extends ArrayAdapter<Trip> { 

    int resource; 
    public MyAdapter(Context context, int resource, ArrayList<Trip> items) { 
     super(context, resource,items); 
     this.resource=resource; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     LinearLayout tripListItemView; 
     final Trip t = getItem(position); 
     String name = t.getName(); 
     boolean offline = t.isOffline() ; 
     if(convertView==null) { 
      tripListItemView = new LinearLayout(getContext()); 
      String inflater = Context.LAYOUT_INFLATER_SERVICE; 
      LayoutInflater vi; 
      vi = (LayoutInflater)getContext().getSystemService(inflater); 
      vi.inflate(resource, tripListItemView, true); 
     } 
     else { 
      tripListItemView = (LinearLayout) convertView; 
     } 
     setProgressBarVisibility(true); 
     View v = findViewById(R.id.downloadprogress); 
     ProgressBar progressHorizontal = (ProgressBar) findViewById(R.id.downloadprogress); 

它總是返回null,喜歡它沒有找到進度條。但是,進度條顯示在列表中,但我需要在適配器內部訪問它。

有人知道解決方案嗎?

感謝

回答

2

在你的代碼奇怪的是,findViewById()ArrayAdapter下訪問......我不明白你的代碼可以編譯如何...

順便說一句,你應該使用在getView(...)參數中傳遞的視圖來檢索您的進度條。

ProgessBar progressBar = (ProgressBar) convertView.findViewById(R.id.downloadprogressbar); 
+0

但在我的情況下,我應該使用triplistview,但答案是正確的。謝謝!! – xger86x 2010-02-25 12:51:01