I have 5 textviews and 4 buttons as shown in the image.When i click the new button,it should fetch the question one by one and if i click the options(A,B,C,D) it should display correct or incorrect.Actually fetching the question works well.But the options part is not working.
I have MainActivity,myAdap.java and layout.xml
MainActivity
public void onClick(View v) {
if (v == b1) {
db = openOrCreateDatabase("quiz.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
if (c1 != null) {
i = c1.getInt(c1.getColumnIndex("qno"));
}
c1 = db.rawQuery("SELECT * FROM donut WHERE qno>'" + i + "' ORDER BY qno LIMIT 1", null);
myAdap adap1 = new myAdap(this, c1);
l1 = (ListView) findViewById(R.id.listView);
l1.setAdapter(adap1);
t2.setText(String.valueOf(i));
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t2 = (TextView) findViewById(R.id.textView20);
b1 = (Button) findViewById(R.id.button2);
b1.setOnClickListener(this);
db.execSQL("CREATE TABLE donut(_id TEXT,optn1 TEXT,optn2 TEXT,optn3 TEXT,optn4 TEXT,qno INTEGER)");
}
myAdap.java
public void bindView(View v, final Context c, Cursor s) {
t0 = (TextView) v.findViewById(R.id.textView11);
TextView t1 = (TextView) v.findViewById(R.id.textView18);
t1.setText(s.getString(s.getColumnIndex(s.getColumnName(0))));
TextView t2 = (TextView) v.findViewById(R.id.textView13);
t2.setText(s.getString(s.getColumnIndex(s.getColumnName(1))));
TextView t3 = (TextView) v.findViewById(R.id.textView14);
t3.setText(s.getString(s.getColumnIndex(s.getColumnName(2))));
TextView t4 = (TextView) v.findViewById(R.id.textView15);
t4.setText(s.getString(s.getColumnIndex(s.getColumnName(3))));
TextView t5 = (TextView) v.findViewById(R.id.textView16);
t5.setText(s.getString(s.getColumnIndex(s.getColumnName(4))));
ob1 = (Button) v.findViewById(R.id.ob1);
ob1.setOnClickListener(this);
ob2 = (Button) v.findViewById(R.id.ob2);
ob2.setOnClickListener(this);
ob3 = (Button) v.findViewById(R.id.ob3);
ob3.setOnClickListener(this);
ob4 = (Button) v.findViewById(R.id.ob4);
ob4.setOnClickListener(this);
}
public void onClick(View v){
if (v == ob1) {
t0.setText(String.valueOf(j));
}
In myAdap,onClick() i just checked whether the cursor fetches the values one by one correct.Even just fetching is not happening.It just displays 0 which i have intialised at the start.
Hope u help me out guys.Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire