2013-03-15 49 views
0

像「誰想成爲百萬富翁」一樣。當用戶按下50/50的幫助按鈕時,我想要兩個錯誤的答案來隱藏,因此要將兩個按鈕的setText設置爲「」,但不是「答案」一個。但我不知道該怎麼做。我正在使用sqlite prepopulated數據庫的問題和答案。我的50/50幫助按鈕是bPolaPola。這是我的遊戲類:如何在測驗中隱藏兩個錯誤答案?

public class NeogranicenoPetGresaka extends SwarmActivity implements OnClickListener{ 

    MyCount brojacVremena = new MyCount(16000, 1000); 

LinkedList<Long> mAnsweredQuestions = new LinkedList<Long>(); 

    private String generateWhereClause(){ 
     StringBuilder result = new StringBuilder(); 
     for (Long l : mAnsweredQuestions){ 
      result.append(" AND _ID <> " + l); 
     } 
     return result.toString(); 
    } 

    Button bIzlazIzKviza, bOdgovor1, bOdgovor2, bOdgovor3, bOdgovor4, bPolaPola; 
    TextView question, netacniOdg, score, countdown; 
    int brojacPogresnihOdgovora = 0; 
    int brojacTacnihOdgovora = 0; 
    public static String tacanOdg; 

    Runnable mLaunchTask = new Runnable() { 
     public void run() { 
      nextQuestion(); 
      brojacVremena.start(); 
     } 
    }; 
    Runnable mLaunchTaskFinish = new Runnable() { 
     public void run() { 
      brojacVremena.cancel(); 
      finish(); 
     } 
     }; 


    private class Answer { 
     public Answer(String opt, boolean correct) { 
      option = opt; 
      isCorrect = correct; 
     } 

     String option; 
     boolean isCorrect; 
    } 
    Handler mHandler = new Handler(); 

    final OnClickListener clickListener = new OnClickListener() { 
     public void onClick(View v) { 

      Answer ans = (Answer) v.getTag(); 
      if (ans.isCorrect) { 
       brojacVremena.cancel(); 
       brojacTacnihOdgovora = brojacTacnihOdgovora + 5; 
       Intent i = new Intent("rs.androidaplikacijekvizopstekulture.TACANODGOVOR"); 
       startActivity(i); 
       mHandler.postDelayed(mLaunchTask,1200); 
      } 
     else{ 
      brojacVremena.cancel(); 
      brojacPogresnihOdgovora++; 
      Intent i = new Intent(getApplicationContext(), PogresanOdgovor.class); 
      i.putExtra("tacanOdgovor", tacanOdg); 
      startActivity(i); 
      mHandler.postDelayed(mLaunchTask,2200); 
      } 
     } 
    }; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

     setContentView(R.layout.neograniceno); 

     Typeface dugmad = Typeface.createFromAsset(getAssets(), "Bebas.ttf"); 
     Typeface pitanje = Typeface.createFromAsset(getAssets(), "myriad.ttf"); 
     bIzlazIzKviza = (Button) findViewById(R.id.bIzlazIzKvizaN); 
     netacniOdg = (TextView) findViewById(R.id.tvBrojPitanjaN); 
     question = (TextView) findViewById(R.id.tvPitanjeN); 
     bOdgovor1 = (Button) findViewById(R.id.bOdgovorN1); 
     bOdgovor2 = (Button) findViewById(R.id.bOdgovorN2); 
     bOdgovor3 = (Button) findViewById(R.id.bOdgovorN3); 
     bOdgovor4 = (Button) findViewById(R.id.bOdgovorN4); 
     bPolaPola = (Button) findViewById(R.id.bPolaPolaN); 
     score = (TextView) findViewById(R.id.tvSkor2N); 
     countdown = (TextView) findViewById(R.id.tvCountdownN); 
     bOdgovor1.setTypeface(dugmad); 
     bOdgovor2.setTypeface(dugmad); 
     bOdgovor3.setTypeface(dugmad); 
     bOdgovor4.setTypeface(dugmad); 
     bPolaPola.setTypeface(dugmad); 
     bIzlazIzKviza.setTypeface(dugmad); 
     netacniOdg.setTypeface(dugmad); 
     question.setTypeface(pitanje); 
     score.setTypeface(dugmad); 
     countdown.setTypeface(dugmad); 

     nextQuestion(); //startuje prvo pitanje! 
     brojacVremena.start(); //startuje brojac vremena 
    } 


    public class MyCount extends CountDownTimer { 

     public MyCount(long millisInFuture, long countDownInterval) { 
      super(millisInFuture, countDownInterval); 
     } 

     @Override 
     public void onFinish() { 
      Intent i = new Intent(getApplicationContext(), PogresanOdgovor.class); 
      i.putExtra("tacanOdgovor", tacanOdg); 
      startActivity(i); 
      mHandler.postDelayed(mLaunchTask,2200); 

      brojacPogresnihOdgovora++; 
     } 

     @Override 
     public void onTick(long millisUntilFinished) { 
      countdown.setText("" + millisUntilFinished/1000); 
     } 
    } 

     public void onClick(View v) { 
     // TODO Auto-generated method stub 


    } 

     @Override public void onStop() { 
      super.onStop(); 
      brojacVremena.cancel(); 
     } 

    @Override 
     protected void onPause() { 
      // TODO Auto-generated method stub 
      super.onPause(); 
     } 

    public void nextQuestion() { 

     TestAdapter mDbHelper = new TestAdapter(this); 
     mDbHelper.createDatabase(); 

     try{ //Pokusava da otvori db 

      mDbHelper.open(); //baza otvorena 

      Cursor c = mDbHelper.getTestData(generateWhereClause()); 
      mAnsweredQuestions.add(c.getLong(0)); 

      List<Answer> labels = new ArrayList<Answer>(); 

      labels.add(new Answer(c.getString(2), true)); 
      labels.add(new Answer(c.getString(3), false)); 
      labels.add(new Answer(c.getString(4), false)); 
      labels.add(new Answer(c.getString(5), false)); 

      Collections.shuffle(labels); 

      tacanOdg = c.getString(2); 

      if(brojacPogresnihOdgovora < 5){ 


     question.setText(c.getString(1)); 

     bOdgovor1.setText(labels.get(0).option); 
     bOdgovor1.setTag(labels.get(0)); 
     bOdgovor1.setOnClickListener(clickListener); 

     bOdgovor2.setText(labels.get(1).option); 
     bOdgovor2.setTag(labels.get(1)); 
     bOdgovor2.setOnClickListener(clickListener); 

     bOdgovor3.setText(labels.get(2).option); 
     bOdgovor3.setTag(labels.get(2)); 
     bOdgovor3.setOnClickListener(clickListener); 

     bOdgovor4.setText(labels.get(3).option); 
     bOdgovor4.setTag(labels.get(3)); 
     bOdgovor4.setOnClickListener(clickListener); 

     netacniOdg.setText("" + brojacPogresnihOdgovora); 
     score.setText("Score: " + brojacTacnihOdgovora); 
      } 
      else{ 
       brojacVremena.cancel(); 
       Intent i = new Intent(getApplicationContext(), Rezultat.class); 
       i.putExtra("noviRezultat", brojacTacnihOdgovora); 
       startActivity(i); 
       mHandler.postDelayed(mLaunchTaskFinish,4000); 
       SwarmLeaderboard.submitScore(6863, brojacTacnihOdgovora); 
      } 
     } 
     finally{ // kada zavrsi sa koriscenjem baze podataka, zatvara db 
      mDbHelper.close(); 
     } 

    bIzlazIzKviza.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      finish(); 
     } 
    }); 
    } 
} 

OK,因爲jazzbassrob指出我需要更加具體。我需要將setText設置爲我的bPolaPola按鈕,「」,爲空字符串,但是我的主要問題是我不知道集合在洗牌後我的答案會結束,所以我不知道要設置哪些按鈕。如何知道我的答案在洗牌後最終結束?

我其實並沒有嘗試任何原因,在這種特定的情況下,我真的不知道從哪裏開始。

+3

恐怕我們不會爲你做。你有什麼嘗試?你有什麼具體的問題嗎? – jazzbassrob 2013-03-15 14:16:04

+0

嘗試將clicklistener應用於bPolaPola? – baboo 2013-03-15 14:16:48

+0

如果您知道4中的哪個答案是正確答案,那麼將其從答案陣列中排除並隨機刪除2個錯誤答案,然後再添加正確答案。 – 2013-03-15 14:24:08

回答

0

如果運行一個查詢,即使在用戶點擊一個查詢之前,查詢也會找到正確的選項,那麼您可以從四個選項中找到正確的按鈕。在此之後,在除指向正確答案的按鈕之外的任意兩個按鈕上使用setText=""