我正在写一个相当复杂的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
一个SimpleCursorAdapter
与ViewBinder
使推出的意图将只需要从主Activity
。但SimpleCursorAdapter
不完全正确,因为我没有将列直接映射到视图。
但是,我在这里的备选方案将建议从游标子类访问主要的Activity
的数据。我觉得必须有更好的方式来设计应用程序。