2013-08-21 19 views
0

考慮如下因素代碼:爲什麼適配器構造函數中的引用沒有更新?

public class MediaItemAdapter extends BaseAdapter { 
    final List<Row> rows; 
    public MediaItemAdapter(Activity activity, ArrayList<HashMap<String, String>> data) { 
     Log.d("mediaadapter", "listcreation: " + data.size()); 
     rows = new ArrayList<Row>();// member variable 
     int i=0; 
     for (HashMap<String, String> addvert:data) { 

      rows.add(new MeadiaRow((LayoutInflater) activity 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE), addvert)); 
      Log.d("mediaadapter", addvert.get("title")); 
      if (i % 20 == 0) { 
       rows.add(new SourseRow((LayoutInflater) activity 
         .getSystemService(Context.LAYOUT_INFLATER_SERVICE))); 
      } 
      i++; 
     } 
    } 

這是我的適配器的構造。在每20個MediaRows之後,我希望添加一個Sourse行。它有ArrayList data。數據總是空的問題。我根據這個tutorial建立我的適配器。在教程中,工作正常。但在教程中,初始數據集是預定義的。在我的凱德初始數據集是空的,並在工作時間填充。但是,在我致電notifyDataSetChanged後,data保持空白(即使數據集不是)。
如何獲取數據的更新值?

+0

檢查該解決方案[這裏](http://stackoverflow.com/questions/3669325/ notifydatasetchanged-示例) –

回答

0

什麼是nesessary做的 - 是將

int i=0; 
     for (HashMap<String, String> addvert:data) { 

      rows.add(new MeadiaRow((LayoutInflater) activity 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE), addvert)); 
      Log.d("mediaadapter", addvert.get("title")); 
      if (i % 20 == 0) { 
       rows.add(new SourseRow((LayoutInflater) activity 
         .getSystemService(Context.LAYOUT_INFLATER_SERVICE))); 
      } 
      i++; 
     } 

從適配器適配器類重寫notifyDataSetChanged

相關問題