0

根据下面的表创建存储返回的查询的更好方法是什么?+

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;
            }
4

1 回答 1

0

返回的查询应该是一个字符串数组,所以我使用下面的代码找出了它。

从我必须返回的数据库处理程序中List<Menu> getItemsAsArray(String Table_Name),然后

我必须将其放入循环中以访问返回的列表并将其放入 mashmap 中。

然后储存起来,ArrayList<HashMap<String, ?>> values2

最后我必须通过以下方式访问它:values2.get(position).get(TAG).toString()

于 2013-08-02T03:05:14.393 回答