Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8815533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:24:14+00:00 2026-06-14T04:24:14+00:00

i’m making an android quiz app. there are have one question an four answers,

  • 0

i’m making an android quiz app. there are have one question an four answers, one of four is true. when user choose wrong answer the game is end, so i want to insert this question and the true answer to database to show it in the listview. but it so difficult with me, please help me some codes. this is my choose answer method:

private void onOptionSelected(String option){

    if(!isGamePaused && !isGameEnded) { 
        ATriviaQuestion tTQuestion = myListOfTriviaQuestions.get(currentQuestionNumber);
        if(option.equals(tTQuestion.GetOptions().get(tTQuestion.GetAnswer() - 1))) {
            correct += 1;
            remainingTime = mySecondsPassed;
            totalPoints += remainingTime * pointsPerRemainingSecond; 
            totalPoints += pointsPerCorrectAnswer;  
            Toast.makeText(PlayGame.this, "chuan cmnr", Toast.LENGTH_SHORT).show();
        }
        else{questionsAsked = totalQuestions;
            incorrect += 1;
            totalPoints -= pointsPerWrongAnswer;
            Toast.makeText(PlayGame.this,tTQuestion.GetOptions().get(tTQuestion.GetAnswer() - 1), Toast.LENGTH_LONG).show();
            isGameEnded=true;
            EndGame();

        }

        mySecondsPassed = config.GetTimeToAnswer();
        UpdateTimerColors(mySecondsPassed);


        if(questionsAsked >= totalQuestions){   
            isGameEnded=true;
            EndGame();
            DisplayResults();
        } else {                    

            currentQuestionNumber=GenerateQuestionNumber();
            PopulateQuestion();
        }

    }else{
        PausedOrEndedGameResponse();
    }
}

and this is my database.java

    public Quanly_congviec(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);

}

@Override
public void onCreate(SQLiteDatabase db) {

    String SQL_String = "CREATE TABLE " + ten_table + "("
            + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," 
            + KEY_NOIDUNG_CONGVIEC + " TEXT,"
            + KEY_THOIGIAN_THUCHIEN + " TEXT, "
            + KEY_MUCDO_QUANTRONG + " TEXT" + ")";
    db.execSQL(SQL_String);

}
@Override
public void onUpgrade(SQLiteDatabase db, int oldversion, int newversion) {

    db.execSQL("DROP TABLE IF EXISTS " + ten_table);


    onCreate(db);   
}


public List<Congviec> getAllCongviec() {
    List<Congviec> CongviecList = new ArrayList<Congviec>();
    String[] ds_dieukien_loc=null; 

    String selectQuery = "SELECT  * FROM " + ten_table;

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, ds_dieukien_loc);


    if (cursor.moveToFirst()) {
        do {
            Congviec Congviec = new Congviec();
            Congviec.set_id(Integer.parseInt(cursor.getString(0)));
            Congviec.setNoidung_congviec(cursor.getString(1));
            Congviec.setThoigian_thuchien(cursor.getString(2));
            Congviec.setMucdo_quantrong(cursor.getString(3));

            CongviecList.add(Congviec);
        } while (cursor.moveToNext());
    }
    db.close();
    return CongviecList;    

}

public void them_congviec(Congviec congviec) {
     SQLiteDatabase db = this.getWritableDatabase();
     String nullColumnHack=null; 
     ContentValues values = new ContentValues();
     if (congviec.get_id()!=-1) values.put(KEY_ID,congviec.get_id());
     values.put(KEY_NOIDUNG_CONGVIEC, congviec.getNoidung_congviec()); 
     values.put(KEY_THOIGIAN_THUCHIEN, congviec.getThoigian_thuchien()); 
     values.put(KEY_MUCDO_QUANTRONG, congviec.getMucdo_quantrong()); 
     db.insert(ten_table, nullColumnHack, values);
     db.close();        
}


public void xoatatca_congviec() {
     SQLiteDatabase db = this.getWritableDatabase();
     String whereClause="";
     String[] whereArgs=null;
     db.delete(ten_table, whereClause, whereArgs);          
     db.close();        
}

public void xoa_1_congviec(int id){
    SQLiteDatabase db= this.getWritableDatabase();
    db.execSQL("delete from  " + ten_table + " where _id="+id);
    db.close();
}

public int sua_1_congviec(Congviec congviec) { 
     SQLiteDatabase db = this.getWritableDatabase(); 
     ContentValues values = new ContentValues(); 
     values.put(KEY_NOIDUNG_CONGVIEC, congviec.getNoidung_congviec());  
     values.put(KEY_THOIGIAN_THUCHIEN, congviec.getThoigian_thuchien());  
     values.put(KEY_MUCDO_QUANTRONG, congviec.getMucdo_quantrong());  

     String whereClause=KEY_ID + "=?"; 
     String[] whereArgs={String.valueOf(congviec.get_id())}; 
     return db.update(ten_table, values, whereClause, whereArgs); 
    } 

}

in the database table has three row but i want to insert the question in row 1, the true answer in row 2 and row three is blank.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:24:16+00:00Added an answer on June 14, 2026 at 4:24 am

    The best database design for this would be to have one row for each question and all of its answers. For a question with four answers, one of which is correct, the column names could be

    _ID
    Question
    CorrectAnswer
    Incorrect1
    Incorrect2
    Incorrect3
    Order

    (I’d use order to set the order in which questions should appear).

    An alternative would be one table to store questions, and another to store answers for each question, but the first option is a lot more simple to handle.

    Final note:
    If your first language isn’t English, it’s natural to use your native language for variable and column names. Alas, most developers use English. Your code is much less readable for me, because I can’t read what is (I presume) Vietnamese. It’s unfair, but there it is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.