· 8 years ago · Jan 21, 2018, 02:00 PM
1package com.android.canadaQbank;
2
3import java.util.ArrayList;
4
5
6
7import android.app.Activity;
8import android.app.ListActivity;
9import android.database.Cursor;
10import android.database.sqlite.SQLiteDatabase;
11import android.database.sqlite.SQLiteException;
12import android.os.Bundle;
13import android.util.Log;
14import android.widget.ArrayAdapter;
15import android.widget.RadioGroup;
16import android.widget.RadioGroup.OnCheckedChangeListener;
17import android.widget.TextView;
18import android.widget.Toast;
19
20public class test extends Activity {
21
22 private final String SAMPLE_DB_NAME = "canadaqbankdatabase";
23 private final String SAMPLE_TABLE_NAME = "tbliapp";
24
25 /** Called when the activity is first created. */
26 @Override
27 public void onCreate(Bundle savedInstanceState) {
28 super.onCreate(savedInstanceState);
29 setContentView(R.layout.test);
30
31 TextView question=(TextView) findViewById(R.id.question);
32 TextView optiona=(TextView) findViewById(R.id.optiona);
33 TextView optionb=(TextView) findViewById(R.id.optionb);
34 TextView optionc=(TextView) findViewById(R.id.optionc);
35 TextView optiond=(TextView) findViewById(R.id.optiond);
36 TextView optione=(TextView) findViewById(R.id.optione);
37
38
39 // ArrayList<String> results = new ArrayList<String>();
40 SQLiteDatabase sampleDB = null;
41
42 try {
43 sampleDB = this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);
44
45 /*sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
46 SAMPLE_TABLE_NAME +
47 " (LastName VARCHAR, FirstName VARCHAR," +
48 " Country VARCHAR, Age INT(3));");*/
49 System.out.println("cursor");
50
51 sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
52 SAMPLE_TABLE_NAME +
53 " (id VARCHAR,category_id TEXT,categoryname TEXT,question TEXT,option1 TEXT," +
54 "option2 TEXT,option3 TEXT,option4 TEXT,option5 TEXT,pictures TEXT," +
55 "answer TEXT,explanation TEXT, Age INT(3));");
56
57
58 sampleDB.execSQL("INSERT INTO " +
59 SAMPLE_TABLE_NAME +
60 " Values ('id','surgeryid','Pediatrics','. An 8 year old boy presents to the physician for a routine" +
61 " health maintenance visit. His mother states that he has had difficulty reading and concentrating " +
62 "in his second-grade class. On examination, seven café-au-lait spots on his body, as well as two " +
63 "small, soft masses above his orbit, are seen. He also has axillary freckling. His mother also has " +
64 "café-au-lait spots on her arms. Which of the following is the most likely diagnosis? ','Congenital hypothyroidism'," +
65 "'Marfan syndrome','Neurofibromatosis','Osteogenesis imperfecta','Tuberous sclerosis','picture','answer','explanation',25);");
66
67
68 /*sampleDB.execSQL("INSERT INTO " +
69 SAMPLE_TABLE_NAME +
70 " Values ('id1','surgeryid','Pediatrics','. The parents of a 10 month old boy presents with a " +
71 "history of excessive straining due when trying to have a bowel movement. On physical exam you " +
72 "clearly see he has developed a rectal prolapse. See picture of rectum protruding through child's " +
73 "anus:What is your next intervention? ','Surgical consult','Sweat chloride test'," +
74 "'Stool studies','Reassurance','Prescribe a stool softener','picture','answer'," +
75 "'explanation',27);");*/
76 /* sampleDB.execSQL("INSERT INTO " +
77 SAMPLE_TABLE_NAME +
78 " Values ('Chittur','Raman','India',25);");
79 sampleDB.execSQL("INSERT INTO " +
80 SAMPLE_TABLE_NAME +
81 " Values ('Solutions','Collabera','India',20);");*/
82
83 Cursor c = sampleDB.rawQuery("SELECT question, Age,option1,option2,option3,option4,option5 FROM " +
84 SAMPLE_TABLE_NAME +
85 " where Age > 10 LIMIT 5", null);
86
87 if (c != null ) {
88 if (c.moveToFirst()) {
89 do {
90 String question1 = c.getString(c.getColumnIndex("question"));
91 int age = c.getInt(c.getColumnIndex("Age"));
92 String opt1 = c.getString(c.getColumnIndex("option1"));
93 String opt2 = c.getString(c.getColumnIndex("option2"));
94 String opt3 = c.getString(c.getColumnIndex("option3"));
95 String opt4 = c.getString(c.getColumnIndex("option4"));
96 String opt5 = c.getString(c.getColumnIndex("option5"));
97 String option1 =" A) "+opt1.trim();
98 String option2 =" B) "+opt2.trim();
99 String option3 =" C) "+opt3.trim();
100 String option4 =" D) "+opt4.trim();
101 String option5 =" E) "+opt5.trim();
102 question.setText(question1);
103 optiona.setText(option1);
104 optionb.setText(option2);
105 optionc.setText(option3);
106 optiond.setText(option4);
107 optione.setText(option5);
108 //results.add("" + question1 + ",Age: " + age + "\n " +" A: " + opt1 + "\n " +"B: " + opt2);
109 }while (c.moveToNext());
110 }
111 }
112
113 //this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));
114
115 } catch (SQLiteException se ) {
116 Log.e(getClass().getSimpleName(), "Could not create or Open the database");
117 } finally {
118 if (sampleDB != null)
119 sampleDB.execSQL("DELETE FROM " + SAMPLE_TABLE_NAME);
120 sampleDB.close();
121 }
122 }
123
124
125}