我正在编写一个相当复杂的ListView
,其中(除其他外)需要在每个列表项中格式化视图。
为了让我完全控制视图在每个列表项中的绑定方式,我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
点击监听器应该基于待处理的意图启动一个活动。未决意图在使用此自定义适配器的活动中实例化。
我知道我可以SimpleCursorAdapter
在 main中使用 aActivity
和 a ViewBinder
,以便只需要从 main 启动意图Activity
。但SimpleCursorAdapter
不太正确,因为我没有将列直接映射到视图。
但是,我在这里的替代方案建议Activity
从游标子类访问 main 的数据。我觉得必须有更好的方法来设计应用程序。