0

テーブルからデータを取得する必要があります。次に、既存のデータを 2 番目のテーブルの別のデータとマージして、出力として表示する必要があります。

ImageSecondPage.java

package main.page;

import android.app.Activity;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;

public class ImagesSecondpage extends Activity
{
     ImageAdapter imgDB = new ImageAdapter(this);

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.image_secondpage);

        imgDB.open();
        Cursor c = imgDB.getAllImages();
        if(c.moveToFirst())
        {
            do
            {
            DisplayImages(c);

            }while(c.moveToNext());
        }
        imgDB.close();

    }

    public void DisplayImages(Cursor c)
    {
        int imageId = getResources().getIdentifier("main.page:drawable/pic1", null, null);
        ImageView imgView = (ImageView) findViewById(R.id.imageView1);
        imgView.setImageResource(imageId);
    }

}

今のところ、アクティビティで画像を表示することしかできませんでした。しかし、要件は、別のテーブルに保存されている人物の名前と一緒に画像を表示する必要があるということです。データベースの別のテーブルから名前を取得する方法がわからないため、表示する名前を取得することに行き詰まっています。
どんな助けでも大歓迎です。どうもありがとう!

4

2 に答える 2

0

私の知る限り、生のクエリを使用する必要があります。rawQuery(sql, selectionArgs);または、各テーブルquery(...)を取得cursorして、それらを相互に比較することもできます。最初の方法ははるかに短いと思いますが、2番目の方法は簡単です!

編集:2番目の方法のサンプルコードについては、この男のチュートリアルvogellaにアクセスできます。最初の方法では、SQLステートメントについてさらに学習する必要があります:W3school。この助けを願っています!

于 2012-08-03T02:00:08.537 に答える
0

最も単純なのは、2つのカーソルを持ち、CursorJoinerを使用して両方を結合することです。

CursorJoiner joiner = new CursorJoiner(cursorA, keyColumnsofA, cursorB, keyColumnsofB);
 for (CursorJointer.Result joinerResult : joiner) {
     switch (joinerResult) {
         case LEFT:
             // handle case where a row in cursorA is unique
             break;
         case RIGHT:
             // handle case where a row in cursorB is unique
             break;
         case BOTH:
             // handle case where a row with the same key is in both cursors
             break;
     }
 }

もう1つのオプションは、SQLiteQueryBuilderを使用し、setTables使用してから、query()メソッドを使用してカーソルを取得することです。

于 2012-08-03T04:30:04.090 に答える