Advertisement
Guest User

Untitled

a guest
Feb 7th, 2017
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.35 KB | None | 0 0
  1. Context context;
  2. private static final String DATABASE_NAME = "DATABASEQUIZ";
  3. private static final int DATABASE_VERSION = 17;
  4. private static final String TABLE_NAME = "TRIVIAQUIZ";
  5. private static final String UID = "_UID";
  6. private static final String QUESTION = "QUESTION";
  7. private static final String OPTA = "OPTA";
  8. private static final String OPTB = "OPTB";
  9. private static final String OPTC = "OPTC";
  10. private static final String OPTD = "OPTD";
  11. private static final String ANSWER = "ANSWER";
  12. private static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " ( " + UID + " INTEGER PRIMARY KEY AUTOINCREMENT , " + QUESTION + " VARCHAR(255), " + OPTA + " VARCHAR(255), " + OPTB + " VARCHAR(255), " + OPTC + " VARCHAR(255), " + OPTD + " VARCHAR(255), " + ANSWER + " VARCHAR(255));";
  13. private static final String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME;
  14.  
  15. public TriviaQuizHelper(Context context) {
  16. super(context, DATABASE_NAME, null, DATABASE_VERSION);
  17. this.context = context;
  18. }
  19.  
  20. @Override
  21. public void onCreate(SQLiteDatabase sqLiteDatabase) {
  22. sqLiteDatabase.execSQL(CREATE_TABLE);
  23.  
  24. }
  25.  
  26. @Override
  27. public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
  28. sqLiteDatabase.execSQL(DROP_TABLE);
  29. onCreate(sqLiteDatabase);
  30.  
  31. }
  32.  
  33. public void allQuestion() {
  34. TriviaQuestion q1 = new TriviaQuestion("Galileo was an Italian astronomer who developed?", "Telescope", "Airoplane", "Electricity", "Train", "Telescope");
  35. this.insert(q1);
  36. TriviaQuestion q2 = new TriviaQuestion("Who is the father of Geometry ?", "Aristotle", "Euclid", "Pythagoras", "Kepler", "Euclid");
  37. this.insert(q2);
  38. TriviaQuestion q3 = new TriviaQuestion("Who was known as Iron man of India ?", "Govind Ballabh Pant", "Jawaharlal Nehru", "Subhash Chandra Bose", "Sardar Vallabhbhai Patel", "Sardar Vallabhbhai Patel");
  39. this.insert(q3);
  40. TriviaQuestion q4 = new TriviaQuestion("The first woman in space was ?", "Valentina Tereshkova", "Sally Ride", "Naidia Comenci", "Tamara Press", "Valentina Tereshkova");
  41. this.insert(q4);
  42. TriviaQuestion q5 = new TriviaQuestion("Who is the Flying Sikh of India ?", "Mohinder Singh", "Joginder Singh", "Ajit Pal Singh", "Milkha singh", "Milkha singh");
  43. this.insert(q5);
  44. TriviaQuestion q6 = new TriviaQuestion("The Indian to beat the computers in mathematical wizardry is", "Ramanujam", "Rina Panigrahi", "Raja Ramanna", "Shakunthala Devi", "Shakunthala Devi");
  45. this.insert(q6);
  46. TriviaQuestion q7 = new TriviaQuestion("Who is Larry Pressler ?", "Politician", "Painter", "Actor", "Tennis player", "Politician");
  47. this.insert(q7);
  48. TriviaQuestion q8 = new TriviaQuestion("Michael Jackson is a distinguished person in the field of ?", "Pop Music", "Jounalism", "Sports", "Acting", "Pop Music");
  49. this.insert(q8);
  50. TriviaQuestion q9 = new TriviaQuestion("The first Indian to swim across English channel was ?", "V. Merchant", "P. K. Banerji", "Mihir Sen", "Arati Saha", "Mihir Sen");
  51. this.insert(q9);
  52. TriviaQuestion q10 = new TriviaQuestion("Who was the first Indian to make a movie?", "Dhundiraj Govind Phalke", " Asha Bhonsle", " Ardeshir Irani", "V. Shantaram", "Dhundiraj Govind Phalke");
  53. this.insert(q10);
  54. TriviaQuestion q11 = new TriviaQuestion("Who is known as the ' Saint of the gutters ?", "B.R.Ambedkar", "Mother Teresa", "Mahatma Gandhi", "Baba Amte", "Mother Teresa");
  55. this.insert(q11);
  56. TriviaQuestion q12 = new TriviaQuestion("Who invented the famous formula E=mc^2", "Albert Einstein", "Galilio", "Sarvesh", "Bill Gates", "Albert Einstein");
  57. this.insert(q12);
  58. TriviaQuestion q13 = new TriviaQuestion("Who is elected as president of us 2016", "Donald Trump", "Hilary Clinton", "Jhon pol", "Barack Obama", "Donald Trump");
  59. this.insert(q13);
  60. TriviaQuestion q14 = new TriviaQuestion("Who was the founder of company Microsoft", "Bill Gates", "Bill Clinton", "Jhon rio", "Steve jobs", "Bill Gates");
  61. this.insert(q14);
  62. TriviaQuestion q15 = new TriviaQuestion("Who was the founder of company Apple ?", "Steve Jobs", "Steve Washinton", "Bill Gates", "Jobs Wills", "Steve Jobs");
  63. this.insert(q15);
  64. TriviaQuestion q16 = new TriviaQuestion("Who was the founder of company Google ?", "Steve Jobs", "Bill Gates", "Larry Page", "Sundar Pichai", "Larry Page");
  65. this.insert(q16);
  66. TriviaQuestion q17 = new TriviaQuestion("Who is know as god of cricket ?", "Sachin Tendulkar", "Kapil Dev", "Virat Koli", "Dhoni", "Sachin Tendulkar");
  67. this.insert(q17);
  68. TriviaQuestion q18 = new TriviaQuestion("who has won ballon d'or of 2015 ?", "Lionel Messi", "Cristiano Ronaldo", "Neymar", "Kaka", "Lionel Messi");
  69. this.insert(q18);
  70. TriviaQuestion q19 = new TriviaQuestion("who has won ballon d'or of 2014 ?", "Neymar", "Lionel Messi", "Cristiano Ronaldo", "Kaka", "Cristiano Ronaldo");
  71. this.insert(q19);
  72. TriviaQuestion q20 = new TriviaQuestion("the Founder of the most famous gaming platform steam is ?", "Bill Cliton", "Bill Williams", "Gabe Newell", "Bill Gates", "Gabe Newell");
  73. this.insert(q20);
  74. }
  75. public void insert(TriviaQuestion triviaQuestion) {
  76. ContentValues contentvalues = new ContentValues();
  77. /* contentvalues.put(UID,triviaQuestion.getId());*/
  78. contentvalues.put(QUESTION, triviaQuestion.getQuestion());
  79. contentvalues.put(OPTA, triviaQuestion.getOpta());
  80. contentvalues.put(OPTB, triviaQuestion.getOptb());
  81. contentvalues.put(OPTC, triviaQuestion.getOptc());
  82. contentvalues.put(OPTD, triviaQuestion.getOptd());
  83. contentvalues.put(ANSWER, triviaQuestion.getAnswer());
  84. SQLiteDatabase db = this.getWritableDatabase();
  85. db.insert(TABLE_NAME, null, contentvalues);
  86. }
  87. public List<TriviaQuestion> getAllQuestion() {
  88. List<TriviaQuestion> que = new ArrayList<>();
  89. SQLiteDatabase db = this.getWritableDatabase();
  90. String coloumns[] = {UID, QUESTION, OPTA, OPTB, OPTC, OPTD, ANSWER};
  91. Cursor cursor = db.query(TABLE_NAME, coloumns, null, null, null, null, null);
  92. while (cursor.moveToNext()) {
  93. TriviaQuestion triviaQuestion = new TriviaQuestion();
  94. triviaQuestion.setId(cursor.getInt(0));
  95. triviaQuestion.setQuestion(cursor.getString(1));
  96. triviaQuestion.setOpta(cursor.getString(2));
  97. triviaQuestion.setOptb(cursor.getString(3));
  98. triviaQuestion.setOptc(cursor.getString(4));
  99. triviaQuestion.setOptd(cursor.getString(5));
  100. triviaQuestion.setAnswer(cursor.getString(6));
  101. que.add(triviaQuestion);
  102. }
  103. return que;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement