i experiencing not emergency problem application works however, understand why behaving this.
there in program method (findfilterintable) 2 string inputs (categoryinterval , paymentinterval).
the method sending request database, finding elements in columns categoryinterval = , paymentinterval = (depending on buttons clicked, choices of user, , on).
there in application radiobutton setting value of paymentinterval :
onclicklistener radiobutton_no_listener = new onclicklistener() { public void onclick(view v) { paymentinterval = null ; } }; onclicklistener radiobutton_yes_listener = new onclicklistener() { public void onclick(view v) { paymentinterval = " " + " '%visa%' " ; } };
so when user clicks button no, means paymentinterval null.
now, here method querying database. crashing while making request in col_payment when paymentinterval null, want change query : if paymentinterval null, not query related column in database (col_payment). , else (if paymentinterval isn't null), query col_payment , collect results.
tried way, didn't work , in despair exchanged statement , works :
public cursor findfilterintable(string categoryinterval, string paymentinterval) { string where; if (paymentinterval != null) { = "(" + col_cat1 + " in " + categoryinterval + " or " + col_cat2 + " in " + categoryinterval + " or " + col_cat3 + " in " + categoryinterval + ") , (" + col_payment + paymentinterval + ") "; } else { = col_cat1 + " in " + categoryinterval + " or " + col_cat2 + " in " + categoryinterval + " or " + col_cat3 + " in " + categoryinterval; } cursor c = mydatabase.query(database_table, new string[] { key_rowid, col_name, col_street, col_website, col_payment, col_telephone, col_price, col_remarks, col_datefriendly }, where, null, null, null, null); return c; }
this code works , opposite of written. when use application:
- if paymentinterval null (the user clicks no), doesn't query col_payment
- if paymentinterval isn't null (and %visa% in case), query database , display right results.
do know causes weird results ?
[edit] listener attached buttons :
radiobutton_yes = (radiobutton) dialogview .findviewbyid(r.id.radiobutton_yes); radiobutton_yes.setonclicklistener(radiobutton_yes_listener); radiobutton_no = (radiobutton) dialogview .findviewbyid(r.id.radiobutton_no); radiobutton_no.setonclicklistener(radiobutton_no_listener);
this code written.
if (paymentinterval != null)
!=
is not equal
operator. so, if paymentinterval not equal null, adds col_payment query; else leaves out.
Comments
Post a Comment