2013-03-18 61 views
0
final String query = "SELECT " + 
       "questiontable.QuestionID, questiontable.answer0, questiontable.answer1, questiontable.answer2, questiontable.answer3, questiontable.answer4, questiontable.Correct, " + 
       " FROM questiontable" + 

       " WHERE questiontable.QuestionID IN (" + 
       allQuestionIds + 
       ") ORDER BY questiontable.QuestionID "; 
     this.cursor = this.db.rawQuery(query, null); 

     if (this.cursor.moveToFirst()) { 
      do { 
       for (final Question q : questions) { 
        if (q.getQuestionId() == this.cursor.getInt(0)) { 
         q.addAnswer(new Answer(this.cursor.getString(1), 
           this.cursor.getString(2), 
           this.cursor.getString(3), 
           this.cursor.getString(4), 
           this.cursor.getString(5), 
           (this.cursor.getInt(6) == 1 ? true : false))); 
        } 
       } 
      } while (this.cursor.moveToNext()); 
     } 
     this.cursor.close(); 

我想補充this.sample(),如:如何使用this.sample() - 而不是this.cursor.getInt()

   q.addAnswer(new Answer(this.sample(), 
            this.cursor.getString(1), 
            this.cursor.getString(2), 
            this.cursor.getString(3), 
            this.cursor.getString(4), 
            this.cursor.getString(5), 
            (this.cursor.getInt(6) == 1 ? true : false))); 

我想要做的:

*創建,將帶我的整數值(AnswerID)的樣品()方法

* AnswerID將是一個整數值,取整數值QuestionID(this.cursor.getInt(0))及其附近;一個數字從0到4.因此,對於每個QuestionID,我將有5個值(10,11,12,13,14 - 20,21,22,23,24 - ......)

*使用this.sample()

我的代碼是我想象的(也可能是完全錯誤的)

void sample (int AnswerID) { 
          for (int i = 0; i < 5; i++) { 
           AnswerID = this.cursor.getInt(0) + i ; 
          } 
         this.sample = sample; 

         } 

回答

1

你不能這樣做,因爲你的方法是無效的。
Void - 不返回任何內容。

void sample (int AnswerID) { 
.. 
} 

如果你要計算的東西,你可以嘗試創建一個返回 整數的ArrayList方法和把它作爲PARAMS到q.addAnswer方法。

public ArrayList<Integer> sample(Cursor cur) { 

    ArrayList<Integer> numbers= new ArrayList<Integer>(); 
    numbers.add(cur.getInt(0));//first test case 
    ... 
    //numbers is array list of integers 
    return numbers; 
} 

所以你可以使用整數arrayList。

+0

真的謝謝你的回答。我是新來的Java和其他代碼混淆。 ** numbers.add(cur.getInt(0)); **添加QuestionID Ithink。所以需要使用:numbers.add(cur.getInt(0)+0); numbers.add(cur.getInt(0)+1); numbers.add(cur.getInt(0)2); ....然後** this.sample()=數字; **之後,我將能夠在q.addAnswer方法中使用this.sample()。我對嗎 ? – santral 2013-03-18 14:31:30

+0

我也想問如何將我的數組列表應用到void 將cur.getInt(0)用於我的無效方法嗎? – santral 2013-03-18 15:18:35

+0

@santral爲我的方法調用它this.sample(this.cursor)。 – Oyeme 2013-03-18 15:34:34