android - Background of fragment dose not change on brodcast receive -


i trying change background of fragment on broadcast receive not change. wanted when user click on button broadcast in order change background of fragment enter image description here menu class: implemented fragment listener , here code implemented function

public class menu extends activity implements setting_fragment.setting_fragmentlistener { view frag;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.menu_activity);     //hide fragment     frag = findviewbyid(r.id.fragment);     frag.setvisibility(view.gone);       }  public void setfragment(view view){     frag.setvisibility(view.visible); }  @override public void closefragment(string txt) {     if(txt=="close"){         frag.setvisibility(view.invisible);     } }  @override public void broadcolor(string col) {     intent = new intent();     bundle b=new bundle();         b.putstring("col",col);         i.putextras(b);         i.setaction("com.example.asus.memory");         i.addflags(intent.flag_include_stopped_packages);         sendbroadcast(i); }} 

this fragment class :

    setting_fragmentlistener commander;     public interface setting_fragmentlistener{         public void closefragment(string txt);         public void broadcolor(string col);     }     @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view v = inflater.inflate(r.layout.setting_fragment, container,false);         final button button = (button) v.findviewbyid(r.id.close);         final button yellow = (button) v.findviewbyid(r.id.yellow);         final button pink = (button) v.findviewbyid(r.id.pink);         final button blue = (button) v.findviewbyid(r.id.blue);         button.setonclicklistener(new view.onclicklistener(){             public void onclick(view v){                 buttonclicked(v);             }         });         pink.setonclicklistener(new view.onclicklistener(){             public void onclick(view v){                 broadpink(v);             }         });         yellow.setonclicklistener(new view.onclicklistener(){             public void onclick(view v){                 broadyel(v);             }         });         blue.setonclicklistener(new view.onclicklistener(){             public void onclick(view v){                 broadbl(v);             }         });         return v;     }      @override     public void onattach(activity activity) {         super.onattach(activity);         try{             commander=(setting_fragmentlistener) activity;         }catch(exception e){}     }      public void buttonclicked(view v){         commander.closefragment("close");     }     public void broadpink(view v){         commander.broadcolor("1");     }     public void broadyel(view v){         commander.broadcolor("2");     }     public void broadbl(view v){         commander.broadcolor("3");     }         public void color(string col){         if (col=="1"){             int rcolor = color.argb(255, 240,118,105);             drawable d= (drawable)getresources().getdrawable(r.drawable.shape);             getview().setbackground(d);         }         if (col=="2"){             int rcolor = color.argb(255, 254,177,1);             getview().setbackgroundcolor(rcolor);         }         if (col=="3"){             int rcolor = color.argb(255, 107,88,193);             getview().setbackgroundcolor(rcolor);         }      }  } 

this receiver class

    setting_fragment sf = new setting_fragment(); win_fragment wf = new win_fragment(); lose_fragment lf = new lose_fragment(); public myreceiver() { }  @override public void onreceive(context context, intent intent) {     bundle =intent.getextras();     string  color = intent.getstringextra("col");     toast.maketext(context,"toast",toast.length_short).show();     sf.color(color);     wf.color(color);     lf.color(color); } 


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -