android - Datepicker and TimePicker dialogs take two clickes of button -


so life of me can not find reason behind needing click twice on start date , start time picker dialog open. have searched these forums many times , have been related edit text fields whereas mine simple button onclicklistener takes 2 hits. in advance.

this class:

package com.shotsevolved.app  import android.content.context; import android.content.intent; import android.os.bundle; import android.support.v4.app.dialogfragment; import android.support.v4.app.fragmentactivity; import android.view.view; import android.view.windowmanager; import android.widget.button; import android.widget.checkbox; import android.widget.compoundbutton; import android.widget.edittext; import android.widget.linearlayout; import android.widget.progressbar; import android.widget.toast; import com.parse.findcallback; import com.parse.parse; import com.parse.parseexception; import com.parse.parsegeopoint; import com.parse.parseobject; import com.parse.parsequery; import com.parse.savecallback; import java.util.list;   public class dealcreator extends fragmentactivity {       string musername;     string companyname;     parsegeopoint location;     string title;     double moldprice;     double mnewprice;     boolean isfree;     boolean isunlimited;     string mdescription;     int muses;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         parse.initialize(this, "ztgl9daaj4xprdns2ro8jnhianntpfcef6v1gm71", "26qmhwwfhmxkfwmvkemaexh2xsfxpo5sr8csuo9v");         getwindow().setflags(windowmanager.layoutparams.flag_fullscreen,                 windowmanager.layoutparams.flag_fullscreen);         setcontentview(r.layout.activity_deal_creator);          final button create = (button)findviewbyid(r.id.createbutton);         final progressbar progress = (progressbar)findviewbyid(r.id.progressicon);         final linearlayout view = (linearlayout)findviewbyid(r.id.linview);         final linearlayout view1 = (linearlayout)findviewbyid(r.id.linview1);         final linearlayout main = (linearlayout)findviewbyid(r.id.mainlinear);         final checkbox freebox = (checkbox)findviewbyid(r.id.freebox);         final edittext oldprice = (edittext)findviewbyid(r.id.oldprice);         final edittext newprice = (edittext)findviewbyid(r.id.newprice);         final checkbox unlimited = (checkbox)findviewbyid(r.id.unlimitedbox);         final edittext uses = (edittext)findviewbyid(r.id.uses);         final button date = (button)findviewbyid(r.id.startdate);         final button time = (button)findviewbyid(r.id.starttime);           create.setvisibility(view.invisible);          intent intent = getintent();         musername = intent.getstringextra("key");          parsequery<parseobject> query = parsequery.getquery("appusers");         query.whereequalto("username", musername);         query.findinbackground(new findcallback<parseobject>() {             public void done(list<parseobject> user, parseexception e) {                 if(user.size() == 1 && e == null){                     int admin = user.get(0).getint("admin");                     if(admin == 2){                          parsequery<parseobject> query = parsequery.getquery("adminnames");                         query.whereequalto("username", musername);                         query.findinbackground(new findcallback<parseobject>() {                             @override                             public void done(final list<parseobject> user, parseexception e) {                                 if(user.size() == 1 && e == null){                                      unlimited.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {                                         @override                                         public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {                                             if(ischecked == true){                                                 uses.setvisibility(view.invisible);                                                 view1.removeview(uses);                                             }else{                                                 uses.setvisibility(view.visible);                                                 view1.addview(uses);                                             }                                         }                                     });                                      freebox.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {                                         @override                                         public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {                                             if(ischecked == true){                                                 oldprice.setvisibility(view.invisible);                                                 newprice.setvisibility(view.invisible);                                                 view.removeview(oldprice);                                                 view.removeview(newprice);                                             }else{                                                 oldprice.setvisibility(view.visible);                                                 newprice.setvisibility(view.visible);                                                 view.addview(oldprice);                                                 view.addview(newprice);                                             }                                         }                                     });                                      date.setonclicklistener(new view.onclicklistener() {                                         @override                                         public void onclick(view v) {                                             showdatepickerdialog(main);                                         }                                     });                                      time.setonclicklistener(new view.onclicklistener() {                                         @override                                         public void onclick(view v) {                                             showtimepickerdialog(main);                                         }                                     });                                      progress.setvisibility(view.gone);                                     view.removeview(progress);                                     create.setvisibility(view.visible);                                      create.setonclicklistener(new view.onclicklistener() {                                         @override                                         public void onclick(view v) {                                             if(freebox.ischecked()){                                                 isfree = true;                                                 moldprice = 0;                                                 mnewprice = 0;                                             }else{                                                  moldprice = double.parsedouble(oldprice.gettext().tostring());                                                 mnewprice = double.parsedouble(newprice.gettext().tostring());                                                 isfree = false;                                             }                                             if(unlimited.ischecked()){                                                 isunlimited = true;                                                 muses = 0;                                             }else{                                                  muses = integer.parseint(uses.gettext().tostring());                                                 isunlimited = false;                                             }                                              //call create deal class                                             deal();                                         }                                     });                                 }else{                                     context context = getapplicationcontext();                                     charsequence text = "error!!! database hacked!";                                     int duration = toast.length_long;                                     toast toast = toast.maketext(context, text, duration);                                     toast.show();                                 }                             }                         });                      }else{                         context context = getapplicationcontext();                         charsequence text = "error!!! not admin!";                         int duration = toast.length_long;                         toast toast = toast.maketext(context, text, duration);                         toast.show();                     }                  }else{                     context context = getapplicationcontext();                     charsequence text = "error!!! database hacked!";                     int duration = toast.length_long;                     toast toast = toast.maketext(context, text, duration);                     toast.show();                 }             }         });     }      private void deal() {          parseobject newdeal = new parseobject("deals");         newdeal.put("uses", muses);         newdeal.put("unlimiteduses", isunlimited);         newdeal.put("description", mdescription);         newdeal.put("free", isfree);         newdeal.put("title", title);         newdeal.put("oldprice", moldprice);         newdeal.put("newprice", mnewprice);         newdeal.put("location", location);         newdeal.put("username", musername);         newdeal.put("companyname", companyname);         newdeal.saveinbackground(new savecallback() {             @override             public void done(parseexception e) {                 context context = getapplicationcontext();                 charsequence text = "deal saved";                 int duration = toast.length_short;                 toast toast = toast.maketext(context, text, duration);                 toast.show();             }         });     }      public void showtimepickerdialog(view v) {         dialogfragment newfragment = new timepickerfragment();         newfragment.show(getsupportfragmentmanager(), "timepicker");     }      public void showdatepickerdialog(view v) {         dialogfragment newfragment = new datepickerfragment();         newfragment.show(getsupportfragmentmanager(), "datepicker");     }  } 

and these fragments:

date:

package com.shotsevolved.app;  import android.app.datepickerdialog; import android.app.dialog; import android.os.bundle; import android.support.v4.app.dialogfragment; import android.widget.datepicker;  import java.util.calendar;   public class datepickerfragment extends dialogfragment         implements datepickerdialog.ondatesetlistener {      @override     public dialog oncreatedialog(bundle savedinstancestate) {         // use current date default date in picker         final calendar c = calendar.getinstance();         int year = c.get(calendar.year);         int month = c.get(calendar.month);         int day = c.get(calendar.day_of_month);          // create new instance of datepickerdialog , return         return new datepickerdialog(getactivity(), this, year, month, day);     }      public void ondateset(datepicker view, int year, int month, int day) {         // date chosen user     } } 

time:

package com.shotsevolved.app;  import android.app.dialog; import android.app.timepickerdialog; import android.os.bundle; import android.support.v4.app.dialogfragment; import android.text.format.dateformat; import android.widget.timepicker;  import java.util.calendar;   public class timepickerfragment extends dialogfragment         implements timepickerdialog.ontimesetlistener {      @override     public dialog oncreatedialog(bundle savedinstancestate) {         // use current time default values picker         final calendar c = calendar.getinstance();         int hour = c.get(calendar.hour_of_day);         int minute = c.get(calendar.minute);          // create new instance of timepickerdialog , return         return new timepickerdialog(getactivity(), this, hour, minute,                 dateformat.is24hourformat(getactivity()));     }      public void ontimeset(timepicker view, int hourofday, int minute) {         // time chosen user     } } 

and xml:

    <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:background="#1e1c1c"     android:id="@+id/root"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >      <linearlayout         android:layout_width="fill_parent"         android:layout_height="@dimen/height"         android:layout_alignparenttop="true"         android:background="@color/purple"         xmlns:android="http://schemas.android.com/apk/res/android">          <linearlayout             android:orientation="horizontal"             android:layout_width="fill_parent"             android:layout_height="fill_parent">              <imagebutton                 android:id="@+id/btn_backfromsettings"                 android:layout_width="@dimen/width"                 android:layout_height="fill_parent"                 android:background="@drawable/ui_button_purple"                 android:contentdescription="@string/desc"                 android:src="@drawable/ico_left" />              <linearlayout                 android:layout_width="@dimen/divider_size"                 android:layout_height="fill_parent"                 android:background="@color/dark_purple" >             </linearlayout>              <textview                 android:id="@+id/mainlogin"                 android:layout_width="0dip"                 android:layout_height="fill_parent"                 android:layout_weight="1"                 android:gravity="center"                 android:tag="bold"                 android:text="@string/dealcreator"                 android:textcolor="@color/white"                 android:textsize="@dimen/tex_size_xxlarge" />              <linearlayout                 android:layout_width="@dimen/divider_size"                 android:layout_height="fill_parent"                 android:background="@color/dark_purple" >             </linearlayout>          </linearlayout>     </linearlayout>        <scrollview         android:layout_width="match_parent"         android:layout_height="match_parent" >          <linearlayout             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:orientation="vertical"             android:id="@+id/mainlinear">              <linearlayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:orientation="vertical"                 android:padding="@dimen/dim_20"                 android:id="@+id/linview">                  <progressbar                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:id="@+id/progressicon"                     android:layout_gravity="center_horizontal" />                  <edittext                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:id="@+id/titleofdeal"                     style="@style/edittext_purple"                     android:hint="title of deal"                     android:layout_gravity="center_horizontal" />                  <edittext                     android:layout_width="match_parent"                     android:layout_height="200dp"                     android:id="@+id/dealdescription"                     android:gravity="top"                     android:layout_margintop="@dimen/dim_10"                     style="@style/edittext_purple"                     android:hint="describe company , deal"                     android:layout_gravity="center_horizontal" />                  <checkbox                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:text="free"                     android:layout_margintop="@dimen/dim_10"                     style="@style/checkbox_purple"                     android:textcolor="@color/offwhite"                     android:id="@+id/freebox" />                  <edittext                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:id="@+id/oldprice"                     android:layout_margintop="@dimen/dim_10"                     style="@style/edittext_purple"                     android:hint="old cost of product"                     android:inputtype="numberdecimal"                     android:layout_gravity="center_horizontal" />                  <edittext                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:id="@+id/newprice"                     android:layout_margintop="@dimen/dim_10"                     android:inputtype="numberdecimal"                     style="@style/edittext_purple"                     android:hint="new cost of product"                     android:layout_gravity="center_horizontal" />                 </linearlayout>                <linearlayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:orientation="vertical"                 android:id="@+id/linview1"                 android:paddingright="@dimen/dim_20"                 android:paddingleft="@dimen/dim_20">                  <checkbox                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:text="unlimited uses"                     style="@style/checkbox_purple"                     android:textcolor="@color/offwhite"                     android:id="@+id/unlimitedbox" />                  <edittext                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:id="@+id/uses"                     android:layout_margintop="@dimen/dim_10"                     style="@style/edittext_purple"                     android:hint="number of uses per customer"                     android:inputtype="number"                     android:layout_gravity="center_horizontal" />              </linearlayout>              <linearlayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:orientation="horizontal"                 android:id="@+id/linview2"                 android:gravity="center_horizontal"                 android:layout_margintop="@dimen/dim_10"                 android:paddingright="@dimen/dim_20"                 android:paddingleft="@dimen/dim_20">                  <button                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:id="@+id/startdate"                     android:layout_margintop="@dimen/dim_10"                     style="@style/edittext_purple"                     android:hint="start date"                     android:layout_marginright="@dimen/dim_10"                     android:layout_gravity="center_horizontal" />                  <button                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:id="@+id/starttime"                     android:layout_margintop="@dimen/dim_10"                     style="@style/edittext_purple"                     android:hint="start time"                     android:layout_gravity="center_horizontal" />              </linearlayout>              <linearlayout                 android:layout_width="fill_parent"                 android:layout_height="fill_parent"                 android:orientation="vertical">                  <linearlayout                     android:layout_width="fill_parent"                     android:layout_height="wrap_content"                     android:orientation="horizontal"                     android:layout_margintop="@dimen/dim_10"                     android:gravity="center_horizontal">                      <button                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:text="set expiry date"                         android:layout_marginright="@dimen/dim_10"                         android:padding="@dimen/dim_10"                         style="@style/button_purple"                         android:id="@+id/datebuttonend"                         android:layout_gravity="center_horizontal" />                      <button                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:text="set expiry time"                         android:padding="@dimen/dim_10"                         style="@style/button_purple"                         android:id="@+id/timebuttonend"                         android:layout_gravity="center_horizontal" />                 </linearlayout>               </linearlayout>                  <button                     android:layout_width="fill_parent"                     android:layout_height="wrap_content"                     android:text="create"                     android:padding="@dimen/dim_10"                     android:layout_margintop="@dimen/dim_10"                     android:layout_marginleft="@dimen/dim_20"                     android:layout_marginright="@dimen/dim_20"                     style="@style/button_purple"                     android:id="@+id/createbutton"                     android:layout_gravity="center_horizontal" />              </linearlayout>     </scrollview>  </linearlayout> 

hmm, code looks ok. can try adding android:focusable="false" buttons. i'm curious if problem you're requesting focus first click , second initiates click.

also, if doesn't help, can put logs in click listener , in public void showtimepickerdialog(view v) { method ... see if it's triggered first click @ all.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -