我从数据库中查询了文本(标题)并将其显示在 TextView 中,但是当它显示时,它不按顺序显示,但它只显示一个标题,并且该标题位于标题列的最后一个索引中。
我怎样才能全部显示并从头到尾排序?
图像适配器
public class ImageAdapter extends BaseAdapter {
private ArrayList<HashMap<String, String>> MyArr = new ArrayList<HashMap<String,String>>();
Cursor cursor = dataSource.database.rawQuery("SELECT * FROM "+CafeDbOpenHelper.TABLE_CAFE, null);
public ImageAdapter(Context c){
context = c;
}
@Override
public int getCount() {
return cursor.getCount();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View converView, ViewGroup parent) {
ViewHolder viewHolder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(converView == null){
converView = inflater.inflate(R.layout.grid_item, null);
}
viewHolder.imageview = (ImageView) converView.findViewById(R.id.imv_card_cafe);
viewHolder.txtTitle = (TextView) converView.findViewById(R.id.txt_title);
while (cursor.moveToNext()) {
Log.i("db", " return "+cursor.getString(cursor.getColumnIndex(TAG_CAFE_TITLE)));
viewHolder.txtTitle.setText(cursor.getString(cursor.getColumnIndex(TAG_CAFE_TITLE)));
}
String imagePath = Environment.getExternalStorageDirectory().toString()+"/downloadedfile.png";
viewHolder.imageview.setImageResource(mThumb[position]);
return converView;
}
}
Logcat db 标签是来自数据库的文本
03-04 14:44:00.411: D/AbsListView(22842): Get MotionRecognitionManager
03-04 14:44:00.426: I/ACTION(22842): Database is open
03-04 14:44:00.442: I/number(22842): return11 rows
03-04 14:44:00.450: I/ACTION(22842): Database is open
03-04 14:44:00.504: I/db(22842): return Kiriya Café
03-04 14:44:00.504: I/db(22842): return Brown Coffee and Bakery
03-04 14:44:00.504: I/db(22842): return The Blue Pumpkin - Riverside
03-04 14:44:00.504: I/db(22842): return Black Canyon Coffee
03-04 14:44:00.559: D/libEGL(22842): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
03-04 14:44:00.575: D/libEGL(22842): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
03-04 14:44:00.575: D/libEGL(22842): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
03-04 14:44:00.684: D/OpenGLRenderer(22842): Enabling debug mode 0
03-04 14:45:35.348: I/ACTION(22842): Database is close
图片