我必须将数据从光标加载到我的应用程序中的列表视图。这是我的自定义适配器类。它工作正常。但我需要为列表视图的第一行显示单独的布局。列表中的第一行将有一个额外的图像视图。我该怎么做?请帮我。提前致谢。
public class CustomSCAdapter extends SimpleCursorAdapter {
Cursor c;
Context context;
Activity activity;
int layout;
public CustomSCAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags ) {
super(context, layout, c, from, to, flags);
this.c = c;
this.context=context;
this.activity=(Activity) context;
this.layout = layout;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view = LayoutInflater.from(context).inflate(this.layout, parent, false);
return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
//here finding all my views in row from view object and binding data from cursor as per my requirement.
}
}
编辑:实际上我正在为适配器类的构造函数的游标变量传递 null,因为我在我的片段中使用加载器机制。
getLoaderManager().initLoader(0, null, this);
adapter = new CustomSCAdapter(getActivity(), R.layout.row_layout, null, from, to, 0);