android - How to check if button is clicked in onclick method in IQ test -
i want write iq test app. used 3 radio buttons answers , button next question. want use button instead of radiobutton. dont know in onclick() method. please me :)
this code:
public void onclick(view view_obj) { if (!radiobt_obj1.ischecked() && !radiobt_obj2.ischecked() && !radiobt_obj3.ischecked()) { toast.maketext(this, "please select", toast.length_long).show(); } else { estimation(); if (btn1.gettext().tostring().equals("next")) { if (!cursor_obj.isafterlast()) { number++; txt_obj.settext(cursor_obj.getstring(cursor_obj .getcolumnindex("question"))); radiobt_obj1.settext(cursor_obj.getstring(cursor_obj .getcolumnindex("ans1"))); radiobt_obj2.settext(cursor_obj.getstring(cursor_obj .getcolumnindex("ans2"))); radiobt_obj3.settext(cursor_obj.getstring(cursor_obj .getcolumnindex("ans3"))); set_invis(); cursor_obj.movetonext(); checked_buttons(); if (!cursor_obj.isafterlast() && number <40) { btn1.settext("next"); } else { btn1.settext("result"); cursor_obj.close(); db.close(); } } } else { intent intent_obj = new intent(anxietyquestion.this,anxietyresult.class); intent_obj.putextra("value", result); startactivity(intent_obj); finish(); } } }
public void estimation() {
switch (number) { case 1: if (radiobt_obj1.ischecked()) { result += 2; } if (radiobt_obj2.ischecked()) { result += 0; } if (radiobt_obj3.ischecked()) { result += 1; } break;
in xml:
<button ... android:onclick="onclicknext" />
in java
(...) public void onclicknext(view v){ (...) }
also can attach different onclick
-listeners on every view
desire, try first work via xml idea of it. don't use 1 single onclick
method, make crazy.
Comments
Post a Comment