onclick - Can't dismiss a custom DialogFragment Android -


i implemented own dialogfragment custom layout, 2 simple buttons. problem not able dismiss it. here there code of layout:

     <?xml version="1.0" encoding="utf-8"?>     <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"         android:orientation="vertical" android:l  ayout_width="match_parent"     android:layout_height="match_parent"     android:weightsum="1">      <imageview         android:layout_width="100dp"         android:layout_height="100dp"         android:id="@+id/imgprofilequestionsender"         android:layout_gravity="center_horizontal" />      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textappearance="?android:attr/textappearancemedium"         android:text="medium text"         android:id="@+id/questiontoanswer"         android:layout_gravity="center_horizontal"         android:padding="10dp" />      <linearlayout         android:orientation="horizontal"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_gravity="center_horizontal">          <button             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="@string/yes"             android:id="@+id/yesbuttonanswer"             android:layout_weight="1"/>          <button             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="@string/no"             android:id="@+id/nobuttonanswer"             android:layout_weight="1"/>     </linearlayout> </linearlayout> 

here there code of dialog

public class questiondialog extends dialogfragment implements view.onclicklistener {  public interface questioninterface{     void yesquestionpressed(int idquestion);     void noquestionpressed(int idquestion); }  private int idquestion;  private questioninterface mquestioninterface; //private dialoginterface.onclicklistener monclicklistener; private button yesbutton, nobutton; private imageview profileimage; private textview question;    @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate){     view view = inflater.inflate(r.layout.layout_dialog_question, null);     nobutton = (button)view.findviewbyid(r.id.nobuttonanswer);     yesbutton = (button)view.findviewbyid(r.id.yesbuttonanswer);     profileimage = (imageview)view.findviewbyid(r.id.imgprofilequestionsender);     question = (textview)view.findviewbyid(r.id.questiontoanswer);     question.settext("here there should text of question retrived using id of question, image on left should image of" +             "the friend sent question, id of question " + string.valueof(getarguments().getint("questionid")));     picasso.with(getactivity().getapplicationcontext()).load("http://i.imgur.com/dvpvklr.png").transform(new circletransform()).fit().centercrop().into(profileimage);       setcancelable(false);     return view;  }   @override public void onclick(view v) {     if(v.getid()==r.id.yesbuttonanswer){          dismiss();         mquestioninterface.yesquestionpressed(getarguments().getint("questionid"));      }     if(v.getid()==r.id.nobuttonanswer){          dismiss();         mquestioninterface.noquestionpressed(getarguments().getint("questionid"));      } }   @override public void onattach(activity activity){     super.onattach(activity);     if(activity instanceof questioninterface) {         mquestioninterface = (questioninterface) activity;      } } 

directly set button click listener in oncreateview(...)

 @override  public view oncreateview(....)  {  .......  .......   negativebutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             dismiss();         }     });      positivebutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             dismiss();         }     });     .......  } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -