java - Getting CheckBox Data into a Bundle -
i've done before. it's not rocket science. beautiful activity containing perfect form. edittext
here... spinner
there. time there checkbox
'es.
this should easy: setup onclick()
method declared in xml, grab id of view...
...thing is, i've been using bundle
gather data in form , send intentservice
drop sqlite database.
/** * called when user changes state of checkbox * @param view view checked/unchecked */ public void oncheckboxchng(view view) { // view checked? boolean checked = ((checkbox) view).ischecked(); string mfield = new string(); // check checkbox clicked switch(view.getid()){ case r.id.dlg_add_ply_chk1: mfield = "platinum"; break; case r.id.dlg_add_ply_chk2: mfield = "gold"; break; case r.id.dlg_add_ply_chk3: mfield = "silver"; break; case r.id.dlg_add_ply_chk4: mfield = "bronze"; break; case r.id.dlg_add_ply_chk5: mfield = "hq"; break; case r.id.dlg_add_ply_chk6: mfield = "aurora-1"; break; } if (checked) { setbundlechk(mfield,1); } else { setbundlechk(mfield,0); } } /** * set boolean fields in mbdlgform based on user action on checkboxes * * @param field field name change * @param state state set (<code>true</code> or <code>false</code> */ private void setbundlechk(string field, int state){ if (buildconfig.debug) { log.i(constants.tag_actdlgaddplyr, "setbundlechk(field, state) called with: "+field+", , "+state); log.i(constants.tag_actdlgaddplyr, "setbundlechk(): mbdlgform keys :"); (string key: mbdlgform.keyset()){ log.d (constants.tag_frgactplayers, "mbdlgform."+key); } } if (state == 1) { mbdlgform.putboolean(field, true); } else { mbdlgform.putboolean(field, false); } }
piece of cake, right?
problem is, though bundle
's scope entire activity, can't been seen in onclick()
callback checkbox
'es nor in function call onclick()
callback...
...please tell me... missing?
even after implementing "activity.this.method()" i'm still getting following logcat messages:
03-04 20:09:32.349: e/androidruntime(641): fatal exception: main 03-04 20:09:32.349: e/androidruntime(641): java.lang.illegalstateexception: not execute method of activity 03-04 20:09:32.349: e/androidruntime(641): @ android.view.view$1.onclick(view.java:3591) 03-04 20:09:32.349: e/androidruntime(641): @ android.view.view.performclick(view.java:4084) 03-04 20:09:32.349: e/androidruntime(641): @ android.widget.compoundbutton.performclick(compoundbutton.java:100) 03-04 20:09:32.349: e/androidruntime(641): @ android.view.view$performclick.run(view.java:16966) 03-04 20:09:32.349: e/androidruntime(641): @ android.os.handler.handlecallback(handler.java:615) 03-04 20:09:32.349: e/androidruntime(641): @ android.os.handler.dispatchmessage(handler.java:92) 03-04 20:09:32.349: e/androidruntime(641): @ android.os.looper.loop(looper.java:137) 03-04 20:09:32.349: e/androidruntime(641): @ android.app.activitythread.main(activitythread.java:4745) 03-04 20:09:32.349: e/androidruntime(641): @ java.lang.reflect.method.invokenative(native method) 03-04 20:09:32.349: e/androidruntime(641): @ java.lang.reflect.method.invoke(method.java:511) 03-04 20:09:32.349: e/androidruntime(641): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 03-04 20:09:32.349: e/androidruntime(641): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 03-04 20:09:32.349: e/androidruntime(641): @ dalvik.system.nativestart.main(native method) 03-04 20:09:32.349: e/androidruntime(641): caused by: java.lang.reflect.invocationtargetexception 03-04 20:09:32.349: e/androidruntime(641): @ java.lang.reflect.method.invokenative(native method) 03-04 20:09:32.349: e/androidruntime(641): @ java.lang.reflect.method.invoke(method.java:511) 03-04 20:09:32.349: e/androidruntime(641): @ android.view.view$1.onclick(view.java:3586) 03-04 20:09:32.349: e/androidruntime(641): ... 12 more 03-04 20:09:32.349: e/androidruntime(641): caused by: java.lang.nullpointerexception 03-04 20:09:32.349: e/androidruntime(641): @ net.clmitchell.ewtraker.pplayers.actdlgaddplyr.setbundlechk(actdlgaddplyr.java:260) 03-04 20:09:32.349: e/androidruntime(641): @ net.clmitchell.ewtraker.pplayers.actdlgaddplyr.oncheckboxchng(actdlgaddplyr.java:231) 03-04 20:09:32.349: e/androidruntime(641): ... 15 more
the 2 line identified @ end are, respectively:
if (checked){actdlgaddplyr.this.setbundlechk(mfield,1);} (string key: actdlgaddplyr.this.mbdlgform.keyset()){
the following 2nd method:
/** * set boolean fields in mbdlgform based on user action on checkboxes * * @param field field name change * @param state state set (<code>true</code> or <code>false</code> */ private void setbundlechk(string field, int state){ if (buildconfig.debug) { log.i(constants.tag_actdlgaddplyr, "setbundlechk(field, state) called with: "+field+", , "+state); log.i(constants.tag_actdlgaddplyr, "setbundlechk(): mbdlgform keys :"); (string key: actdlgaddplyr.this.mbdlgform.keyset()){ log.d (constants.tag_frgactplayers, "mbdlgform."+key); } } if(state == 1){actdlgaddplyr.this.mbdlgform.putboolean(field, true);} else{actdlgaddplyr.this.mbdlgform.putboolean(field, false);} }
try out:-
activity.this.setbundlechk(mfield,1);
Comments
Post a Comment