android - Sending changing Data from View to Fragment -


i have activity , layout contains customview in i'm able draw , got fragment in i'll make statistic used colors, stroke widths , 1 other variable. have send information fragment.

how can that?

my first idea make lists colors, strokes..., adding every drawing color list made of, getting size of list , @ last sending fragment.

or make variable , every time color, stroke width , variable added, specific variable increase, here's same problem don't know how send value fragment.

the second problem variable changing, if made 1 small line in red , go statisitc should 1 small red line. if make one, should 2 small red lines, how can receive latest value of these values?

you can create interface communicate between view , fragment. read more java interfaces here

public class drawview extends view {     private oncolorchangedlistener mlistener;      //     public interface oncolorchangedlistener {         public void colorchanged(int color);     }      public void setoncolorchangedlistener(oncolorchangedlistener listener){         mlistener = listener;         //call method implement interface in fragment     }      @override     public void ondraw(canvas canvas){         if(mlistener != null){             mlistener.colorchanged(somecolor);         }     } }  public class somefragment extends fragment implements oncolorchangedlistener {     public void oncreate(){         drawview v = new drawview();         v.setoncolorchangedlistener(this);     }     //if class claims implement interface, methods defined interface must appear in source code before class compile.      public void colorchanged(int color){         //do stuff color     } } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -