1

我正在寫一個相當複雜的ListView,其中(除其他外)需要在每個列表項中格式化視圖。在CursorAdapter子類中訪問活動的狀態

給我過的觀點是如何在每個列表項約束的完全控制,我以這種方式子類CursorAdapter

public class MyAdapter extends CursorAdapter { 

    public final LayoutInflater mInflater; 

    public MyAdapter(Context context, Cursor c) { 
     super(context, c); 
     mInflater = LayoutInflater.from(context); 
    } 

    @Override 
    public void bindView(View view, Context context, Cursor cursor) { 
     final ToggleButton tButton = (ToggleButton) view.findViewById(R.id.tbutton); 
     tButton.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) { 
       // start activity based on a pending intent 
      } 
     });  

    } 
} 

的問題是,我ToggleButton點擊監聽,應該基於一個未決開始活動意圖。掛起的意圖在利用該定製適配器的活動中被實例化。

我知道我可以用在主Activity一個SimpleCursorAdapterViewBinder使推出的意圖將只需要從主Activity。但SimpleCursorAdapter不完全正確,因爲我沒有將列直接映射到視圖。

但是,我在這裏的備選方案將建議從遊標子類訪問主要的Activity的數據。我覺得必須有更好的方式來設計應用程序。

回答