Android: IllegalStateException:Custom actionbar with onClickListener on icons -


hi have custom actionbar reset icon , , have sliding menu fragments. when in fragmenta , when clicked on reset icon reset values of particular fragment in case fragmenta.

the problem when come fragmentb fragmenta clicking backbutton , when click actionbar reset calling reset method in fragmentb.

below how calling onclick event in both fragments.

fragment a

((fragmentchangeactivity) getactivity()).housing_reset.setontouchlistener(new ontouchlistener() {          @override         public boolean ontouch(view v, motionevent event) {             resetallfragmentafields();             return false;         }     }); 

frgament b

   ((fragmentchangeactivity) getactivity()).housing_reset.setontouchlistener(new ontouchlistener() {              @override             public boolean ontouch(view v, motionevent event) {                 resetallfragmentbfields();                 return false;             }         }); 

how mention click event of reset icon belongs particular fragment.

getting crash below log

09-02 14:52:43.805: e/messagequeue-jni(31011): java.lang.illegalstateexception: fragment fragemntb not attached activity 


Comments