最好使用分隔符枚举。但在你的情况下
public Cursor getItemList(){
return db.rawQuery("SELECT * FROM Items NATURAL JOIN Separators ON Item.separator_id = Separators._id");
}
创建您的自定义 CursorAdapter 并以您的方式在 bindView 方法中管理它。带有视图分隔符的布局应包含 ImageView 作为分隔符。
public class MyCursorAdapter extends CursorAdapter {
LayoutInflater inflater;
public MyCursorAdapter(Context context, Cursor c) {
super(context, c);
inflater = LayoutInflater.from(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
//cursor is already setted to requared position, just get your column
TextView tv1 = (TextView)view.findViewById(R.id.textView1);
TextView tv2 = (TextView)view.findViewById(R.id.textView2);
tv1.setText(cursor.getString(1));
tv2.setText(cursor.getString(2));
ImageView myImageView = (ImageView)fimdViewById(R.id.my_image_view);
if(cursor.getString(5) == "line"){
myImageView = getResources().getIdentifier("yourpackagename:drawable/line.png");
}else if(cursor.getString(5) == "wave"){
myImageView = getResources().getIdentifier("yourpackagename:drawable/wave.png");
...
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
//here is view for each raws
return inflater.inflate(R.layout.my_raw_view, parent, false);
}
}