它更好地處理分隔符的enum 。 但在你的情況下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);
}
}