根据下面的表创建存储返回的查询的更好方法是什么?+
String CREATE_ITEMS = "CREATE TABLE " + TABLE_ITEMS + "(" + KEY_ID + " TEXT," + KEY_NAME + " TEXT," + KEY_PRICE + " TEXT," + KEY_ITEM_ID + " TEXT," + KEY_IMAGE_PATH + " NVARCHAR(1000)" +")";
我之所以需要来自 的记录,是TABLE_ITEMS
因为我需要在 GridView 方法中使用KEY_IMAGE_PATH
. 但我的主要问题是如何存储每列的所有记录,以便我可以跟踪网格视图中显示的每个项目的价格和 image_path 是多少?
public String[] getImagePath(){
List<String> paths = new ArrayList<String>();
String selectQuery = "SELECT "+ KEY_IMAGE_PATH +" FROM " + TABLE_ITEMS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
paths.add(cursor.getString(0).toString());
Log.d("getPathImage:", cursor.getString(0).toString());
} while (cursor.moveToNext());
}
db.close();
//This should be returned as array string
return paths.toArray(new String[paths.size()]);
}
它应该是,
-itemid
-sellingPrice
-keyid
-imagePath[position]
-keyname
LoadMainMenuActivity
paths = db.getImagePath();
intent.putExtra(Extra.IMAGES, paths);
ImageGridActivity
Bundle bundle = getIntent().getExtras();
imageUrls = bundle.getStringArray(Extra.IMAGES);
//The images in only displayed but not the other details.
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolder holder;
if (convertView == null) {
view = getLayoutInflater().inflate(R.layout.item_grid_image, parent, false);
holder = new ViewHolder();
holder.text = (TextView) view.findViewById(R.id.text1);
holder.image = (ImageView) view.findViewById(R.id.imageView1);
holder.br = (RatingBar) view.findViewById(R.id.rBarHere);
holder.br.setIsIndicator(true);
holder.br.setFocusable(false);
holder.br.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
//Toast.makeText(getBaseContext(), "Rating:"+rating, Toast.LENGTH_SHORT).show();
}});
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.text.setText("NAAA NA");
holder.br.setStepSize(1);
holder.br.setFocusable(false);
Log.d("Image Path Value in GridView: ", imageUrls[position].toString());
imageLoader.displayImage(imageUrls[position], holder.image, options);
return view;
}