我正在使用SQLite数据库进行测验,我从数据库中提取的问题和答案似乎没有改变到我在XML文件中设置的大小。我把它缩小到从数据库中提取的东西,所以我想知道为什么它只是那个。这是所涉及的所有课程
DBHelper
public class DBHelper extends SQLiteOpenHelper
{
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "triviaQuiz";
// tasks table name
private static final String TABLE_QUEST = "quest";
// tasks Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_QUES = "question";
private static final String KEY_ANSWER = "answer"; //correct option
private static final String KEY_OPTA= "opta"; //option a
private static final String KEY_OPTB= "optb"; //option b
private static final String KEY_OPTC= "optc"; //option c
private SQLiteDatabase dbase;
@Override
public void onCreate(SQLiteDatabase db) {
dbase=db;
String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_QUEST + " ( "
+ KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_QUES
+ " TEXT, " + KEY_ANSWER+ " TEXT, "+KEY_OPTA +" TEXT, "
+KEY_OPTB +" TEXT, "+KEY_OPTC+" TEXT)";
db.execSQL(sql);
addQuestions();
//db.close();
}
private void addQuestions()
{
Question q1=new Question("8 X 2 " + "=","16", "20", "18", "16");
this.addQuestion(q1);
Question q2=new Question("8 X 3 " + "=", "20", "24", "26", "24");
this.addQuestion(q2);
Question q3=new Question("8 X 4 " + " =","30", "35","32","32");
this.addQuestion(q3);
Question q4=new Question("8 X 5 " + " = ", "40", "38", "41","40");
this.addQuestion(q4);
Question q5=new Question("8 X 6 " +" =","45","48","50","48");
this.addQuestion(q5);
Question q6=new Question("8 X 7 " +" =","55","56","58","56");
this.addQuestion(q6);
Question q7=new Question("8 X 8 " +" =","64","68","60","64");
this.addQuestion(q7);
Question q8=new Question("8 X 9 " +" =","75","72","70","72");
this.addQuestion(q8);
Question q9=new Question("8 X 10 " +" =","81","89","80","80");
this.addQuestion(q9);
Question q10=new Question("8 X [ ] " +" = 8","1","9","5","1");
this.addQuestion(q10);
Question q11=new Question("8 X [ ] " +" = 24","5","3","6","3");
this.addQuestion(q11);
Question q12=new Question("8 X [ ] " +" = 40","6","9","5","5");
this.addQuestion(q12);
Question q13=new Question("8 X [ ] " +" = 56","7","8","9","7");
this.addQuestion(q13);
Question q14=new Question("8 X [ ] " +" = 80","7","10","9","10");
this.addQuestion(q14);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUEST);
// Create tables again
onCreate(db);
}
// Adding new question
public void addQuestion(Question quest) {
//SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_QUES, quest.getQUESTION());
values.put(KEY_ANSWER, quest.getANSWER());
values.put(KEY_OPTA, quest.getOPTA());
values.put(KEY_OPTB, quest.getOPTB());
values.put(KEY_OPTC, quest.getOPTC());
// Inserting Row
dbase.insert(TABLE_QUEST, null, values);
}
public List<Question> getAllQuestions() {
List<Question> quesList = new ArrayList<Question>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_QUEST;
dbase=this.getReadableDatabase();
Cursor cursor = dbase.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Question quest = new Question();
quest.setID(cursor.getInt(0));
quest.setQUESTION(cursor.getString(1));
quest.setANSWER(cursor.getString(2));
quest.setOPTA(cursor.getString(3));
quest.setOPTB(cursor.getString(4));
quest.setOPTC(cursor.getString(5));
quesList.add(quest);
} while (cursor.moveToNext());
}
// return quest list
return quesList;
}
public int rowcount()
{
int row=0;
String selectQuery = "SELECT * FROM " + TABLE_QUEST;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
row=cursor.getCount();
return row;
}
}
Exercise.java
public class Exercise1 extends Activity
{
List<Question> quesList;
int score=0;
int qid=0;
Question currentQ;
TextView txtQuestion;
Button rda, rdb, rdc;
Button butNext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.exercise1);
DBHelper db=new DBHelper(this);
quesList=db.getAllQuestions();
currentQ=quesList.get(qid);
txtQuestion=(TextView)findViewById(R.id.textView1);
rda=(Button)findViewById(R.id.radio0);
rdb=(Button)findViewById(R.id.radio1);
rdc=(Button)findViewById(R.id.radio2);
//butNext=(Button)findViewById(R.id.button1);
setQuestionView();
rda.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
String s = currentQ.getANSWER();
Log.d("Exercise", s);
if(currentQ.getANSWER().equals(rda.getText()))
{
score++;
if(qid<4)
{
currentQ=quesList.get(qid);
setQuestionView();
}
else
{
Intent intent = new Intent(Exercise1.this, Tables2.class);
Bundle b = new Bundle();
b.putInt("score", score); //Your score
intent.putExtras(b); //Put your score to your next Intent
startActivity(intent);
finish();
}
}
else
{
Log.d("Exercise", "not working ");
}
}
});
rdb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Log.d("Exercise", "Button B pressed");
if(currentQ.getANSWER().equals(rdb.getText()))
{
score++;
if(qid<4)
{
currentQ=quesList.get(qid);
setQuestionView();
}
else
{
Intent intent = new Intent(Exercise1.this, Tables2.class);
Bundle b = new Bundle();
b.putInt("score", score); //Your score
intent.putExtras(b); //Put your score to your next Intent
startActivity(intent);
finish();
}
}
else
{
Log.d("Exercise", "not working");
}
}
});
rdc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Log.d("Exercise", "Button C pressed");
if(currentQ.getANSWER().equals(rdc.getText()))
{
score++;
Log.d("Exercise", "Wrong Answer");
if(qid<4)
{
currentQ=quesList.get(qid);
setQuestionView();
}
else
{
Intent intent = new Intent(Exercise1.this, Tables2.class);
Bundle b = new Bundle();
b.putInt("score", score); //Your score
intent.putExtras(b); //Put your score to your next Intent
startActivity(intent);
finish();
}
}
else
{
Log.d("Exercise", "not workingr");
}
}
});
}
private void setQuestionView()
{
txtQuestion.setText(currentQ.getQUESTION());
rda.setText(currentQ.getOPTA());
rdb.setText(currentQ.getOPTB());
rdc.setText(currentQ.getOPTC());
qid++;
}
}
exercise.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".QuizActivity"
android:background="@drawable/exercise" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="200sp"
android:text="Large Text"
android:textSize="50sp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/radio0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="RadioButton" />
<Button
android:id="@+id/radio1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
<Button
android:id="@+id/radio2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
</LinearLayout>
我会在这里假设它为什么我的文字大小没有改变