public class MainActivity extends Activity { SQLiteDatabase mDb; DB mHelper; Button exec_bt_back; Button exec_bt_next; int check_exp = 1; TextView exec_txt1; TextView exec_txt2; TextView ques; RadioButton ans1, ans2, ans3, ans4; List<Question> quesList; int score=0; //int qid=0; String getAllQuestions; Question currentQ; TextView txtQuestion; int [] srun_ex = new int [40]; Button send; @Override protected void onCreate(Bundle savedInstanceState) { setTheme(android.R.style.Theme_Holo_Light); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); exec_txt1 = (TextView) findViewById(R.id.exec_txt1); exec_txt2 = (TextView) findViewById(R.id.exec_txt2); srun_ex[1] = 30; srun_ex[2] = 40; srun_ex[3] = 2; srun_ex[4] = 32; srun_ex[5] = 12; exec_txt2.setText("11="+srun_ex[1]); exec_bt_next = (Button) findViewById(R.id.exec_bt_next); exec_bt_next.setOnClickListener(new OnClickListener(){ public void onClick(View v) { if (check_exp < 3) { check_exp = check_exp +1; exec_txt1.setText(""+check_exp); exec_txt2.setText(""+srun_ex[check_exp]); exam_run(srun_ex[check_exp-1]); } }}); exec_bt_back = (Button) findViewById(R.id.exec_bt_back); exec_bt_back.setOnClickListener(new OnClickListener(){ public void onClick(View v) { if (check_exp > 1) { check_exp = check_exp -1 ; exec_txt1.setText(""+check_exp); exec_txt2.setText(""+srun_ex[check_exp]); exam_run(srun_ex[check_exp-1]); } }}); checkDatabase(); DB db=new DB(this); quesList=db.getAllQuestions(); currentQ=quesList.get(srun_ex[0]); ques=(TextView)findViewById(R.id.question); ans1 = (RadioButton)findViewById(R.id.one); ans2 = (RadioButton)findViewById(R.id.two); ans3 = (RadioButton)findViewById(R.id.three); ans4 = (RadioButton)findViewById(R.id.four); send=(Button)findViewById(R.id.sen); setQuestionView(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } private void setQuestionView() { ques.setText(currentQ.getquestion()); ans1.setText(currentQ.getans_one()); ans2.setText(currentQ.getans_two()); ans3.setText(currentQ.getans_three()); ans4.setText(currentQ.getans_four()); //qid++; send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); } public void exam_run(int sqit) { RadioGroup grp=(RadioGroup)findViewById(R.id.radioGroup1); RadioButton answer=(RadioButton)findViewById(grp.getCheckedRadioButtonId()); if(currentQ.getanswer().equals(answer.getText())) { score++; } currentQ=quesList.get(sqit); setQuestionView(); } public void checkDatabase() { String url = "/data/data/" + getPackageName() + "/databases/MyDB"; File f = new File(url); if(!f.exists()) { try { mHelper = new DB(this); mDb = mHelper.getWritableDatabase(); mDb.close(); mHelper.close(); InputStream in = getAssets().open("MyDB"); OutputStream out = new FileOutputStream(url); byte[] buffer = new byte[in.available()]; in.read(buffer); out.write(buffer, 0, buffer.length); in.close(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } public void onPause() { super.onPause(); mHelper.close(); mDb.close(); } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง