2016-04-19 11 views
1

これらのテキストタイプの質問 私はそれらを画像のタイプの質問 に説明したいと思います 私は画像になりたい質問は(5 + 2)、(2 + 15)、... 。 は可能ですか??? 私はあなたがいくつかのオプションを持っているアンドロイドクイズをテキストタイプからアンドロイドの画像タイプに切り替えるにはどうすればいいですか?

public void onCreate(SQLiteDatabase db) { 
 
\t \t dbase = db; 
 
\t \t String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_QUEST + " (" 
 
\t \t \t \t + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_QUES 
 
\t \t \t \t + " TEXT, " + KEY_ANSWER + " TEXT, " + KEY_OPTA + " TEXT, " 
 
\t \t \t \t + KEY_OPTB + " TEXT, " + KEY_OPTC + " TEXT)"; 
 
\t \t db.execSQL(sql); 
 
\t \t addQuestion(); 
 
\t \t // db.close(); 
 
\t } 
 
\t private void addQuestion() { 
 
\t \t Question q1 = new Question("5+2 = ?", "7", "8", "6", "7"); 
 
\t \t this.addQuestion(q1); 
 
\t \t Question q2 = new Question("2+18 = ?", "18", "19", "20", "20"); 
 
\t \t this.addQuestion(q2); 
 
\t \t Question q3 = new Question("10-3 = ?", "6", "7", "8", "7"); 
 
\t \t this.addQuestion(q3); 
 
\t \t Question q4 = new Question("5+7 = ?", "12", "13", "14", "12"); 
 
\t \t this.addQuestion(q4); 
 
\t \t Question q5 = new Question("3-1 = ?", "1", "3", "2", "2"); 
 
\t \t this.addQuestion(q5); 
 
\t \t Question q6 = new Question("0+1 = ?", "1", "0", "10", "1"); 
 
\t \t this.addQuestion(q6); 
 
\t \t Question q7 = new Question("9-9 = ?", "0", "9", "1", "0"); 
 
\t \t this.addQuestion(q7); 
 
\t \t Question q8 = new Question("3+6 = ?", "8", "7", "9", "9"); 
 
\t \t this.addQuestion(q8); 
 
\t \t Question q9 = new Question("1+5 = ?", "6", "7", "5", "6"); 
 
\t \t this.addQuestion(q9); 
 
\t \t Question q10 = new Question("7-5 = ?", "3", "2", "6", "2"); 
 
\t \t this.addQuestion(q10); 
 
\t \t Question q11 = new Question("7-2 = ?", "7", "6", "5", "5"); 
 
\t \t this.addQuestion(q11); 
 
\t \t Question q12 = new Question("3+5 = ?", "8", "7", "5", "8"); 
 
\t \t this.addQuestion(q12); 
 
\t \t Question q13 = new Question("0+6 = ?", "7", "6", "5", "6"); 
 
\t \t this.addQuestion(q13); 
 
\t \t Question q14 = new Question("12-10 = ?", "1", "2", "3", "2"); 
 
\t \t this.addQuestion(q14); 
 
\t \t Question q15 = new Question("12+2 = ?", "14", "15", "16", "14"); 
 
\t \t this.addQuestion(q15); 
 
\t \t Question q16 = new Question("2-1 = ?", "2", "1", "0", "1"); 
 
\t \t this.addQuestion(q16); 
 
\t \t Question q17 = new Question("6-6 = ?", "6", "12", "0", "0"); 
 
\t \t this.addQuestion(q17); 
 
\t \t Question q18 = new Question("5-1 = ?", "4", "3", "2", "4"); 
 
\t \t this.addQuestion(q18); 
 
\t \t Question q19 = new Question("4+2 = ?", "6", "7", "5", "6"); 
 
\t \t this.addQuestion(q19); 
 
\t \t Question q20 = new Question("5+1 = ?", "6", "7", "5", "6"); 
 
\t \t this.addQuestion(q20); 
 
\t \t Question q21 = new Question("5-4 = ?", "5", "4", "1", "1"); 
 
\t \t this.addQuestion(q21); 
 
\t \t // END 
 
\t } 
 
\t @Override 
 
\t public void onUpgrade(SQLiteDatabase db, int oldV, int newV) { 
 
\t \t // Drop older table if existed 
 
\t \t db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUEST); 
 
\t \t // Create tables again 
 
\t \t onCreate(db); 
 
\t } 
 
\t // Adding new question 
 
\t public void addQuestion(Question quest) { 
 
\t \t // SQLiteDatabase db = this.getWritableDatabase(); 
 
\t \t ContentValues values = new ContentValues(); 
 
\t \t values.put(KEY_QUES, quest.getQUESTION()); 
 
\t \t values.put(KEY_ANSWER, quest.getANSWER()); 
 
\t \t values.put(KEY_OPTA, quest.getOPTA()); 
 
\t \t values.put(KEY_OPTB, quest.getOPTB()); 
 
\t \t values.put(KEY_OPTC, quest.getOPTC()); 
 
\t \t // Inserting Row 
 
\t \t dbase.insert(TABLE_QUEST, null, values); 
 
\t } 
 
\t public List<Question> getAllQuestions() { 
 
\t \t List<Question> quesList = new ArrayList<Question>(); 
 
\t \t // Select All Query 
 
\t \t String selectQuery = "SELECT * FROM " + TABLE_QUEST; 
 
\t \t dbase = this.getReadableDatabase(); 
 
\t \t Cursor cursor = dbase.rawQuery(selectQuery, null); 
 
\t \t // looping through all rows and adding to list 
 
\t \t if (cursor.moveToFirst()) { 
 
\t \t \t do { 
 
\t \t \t \t Question quest = new Question(); 
 
\t \t \t \t quest.setID(cursor.getInt(0)); 
 
\t \t \t \t quest.setQUESTION(cursor.getString(1)); 
 
\t \t \t \t quest.setANSWER(cursor.getString(2)); 
 
\t \t \t \t quest.setOPTA(cursor.getString(3)); 
 
\t \t \t \t quest.setOPTB(cursor.getString(4)); 
 
\t \t \t \t quest.setOPTC(cursor.getString(5)); 
 
\t \t \t \t quesList.add(quest); 
 
\t \t \t } while (cursor.moveToNext()); 
 
\t \t } 
 
\t \t // return quest list 
 
\t \t return quesList; 
 
\t } 
 
}

答えて

0

で始まっています。そのうちの2つ:

マップの使用 キーをデータベースの質問IDとしてください。各キーのマップに格納された値は、ビュー(たとえば、リソースとしてロード)

をDB にフィールドを追加画像は画像の相対パスを持つフィールドを追加し、すべてのための対応する画像をロードすることができ質問。

あなたのDB内の文字列としてパスを格納し、このようイメージを回復することができます

File imgFile = new File("/path/of/image/image.jpg"); 

if(imgFile.exists()){ 

    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); 

    // This image view is defined as a resource.... just set the bitmap 
    ImageView myImage = (ImageView) findViewById(R.id.anyImageView); 
    myImage.setImageBitmap(myBitmap); 

} 
+0

フィールドに画像を追加するには? –

+0

私の編集を参照し、パスから画像をロードする方法 – Jorge

+0

申し訳ありませんが、それは動作しません –

0

は、このコードは、カスタムテキスト
ドンから画像を生成

Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.yourimage); // the original file yourimage.jpg i added in resources 
Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888); 

String yourText = "3+5 = ?"; 

Canvas cs = new Canvas(dest); 
Paint tPaint = new Paint(); 
tPaint.setTextSize(35); 
tPaint.setColor(Color.BLUE); 
tPaint.setStyle(Style.FILL); 
cs.drawBitmap(src, 0f, 0f, null); 
float height = tPaint.measureText("yY"); 
float width = tPaint.measureText(yourText); 
float x_coord = (src.getWidth() - width)/2; 
cs.drawText(yourText, x_coord, height+15f, tPaint); // 15f is to put space between top edge and the text, if you want to change it, you can 
try { 
    dest.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("/sdcard/ImageAfterAddingText.jpg"))); 
    // dest is Bitmap, if you want to preview the final image, you can display it on screen also before saving 
} catch (FileNotFoundException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

このコードを試してみてくださいマニフェストファイルにアクセス許可を追加するのを忘れないでください。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
関連する問題