android - Add or remove image associated with id and tag -


add or remove image along id

in above image i'm having array of images added linearlayout inside horizontal scrollview need add or remove image along id on top of pink heart background , every image having count showing flowers quantity in numbers e.g 4 or 5 maintain count if selected flower removed or added.i don't know how image id , remove image if tap 2 times on pink heart background drag , drop images on screen.any suggestions searched lot..

make_back.xml <?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="@android:color/white">      <include         android:id="@+id/topbar"         layout="@layout/top_bar"         android:layout_width="match_parent"         android:layout_height="wrap_content" />      <linearlayout         android:id="@+id/background_ll"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_above="@+id/gallery_ll"         android:layout_below="@+id/topbar"         android:orientation="vertical">          <imageview             android:id="@+id/backgroundimage"             android:layout_width="match_parent"             android:layout_height="match_parent" />      </linearlayout>       <linearlayout         android:id="@+id/gallery_ll"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_above="@+id/horizontalscrollview"         android:background="@android:color/white"         android:weightsum="1">          <linearlayout             android:id="@+id/flower_ll"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_gravity="center_horizontal"             android:layout_weight=".25"             android:background="@drawable/green_square"             android:gravity="center">              <imageview                 android:id="@+id/flowerimage"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:background="@drawable/flower_n" />         </linearlayout>          <linearlayout             android:id="@+id/ballon_ll"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_gravity="center_horizontal"             android:layout_weight=".25"             android:background="@drawable/green_square"             android:gravity="center">              <imageview                 android:id="@+id/ballonimage"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_gravity="center"                 android:background="@drawable/balloon_g" />         </linearlayout>          <linearlayout             android:id="@+id/teddy_ll"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_gravity="center_horizontal"             android:layout_weight=".25"             android:background="@drawable/green_square"             android:gravity="center">              <imageview                 android:id="@+id/teddy_image"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:background="@drawable/teddy_g" />         </linearlayout>          <linearlayout             android:id="@+id/textfont_ll"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_gravity="center_horizontal"             android:layout_weight=".25"             android:background="@drawable/green_square"             android:gravity="center">              <imageview                 android:id="@+id/textfontimage"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:background="@drawable/text_g" />         </linearlayout>     </linearlayout>      <horizontalscrollview         android:id="@+id/horizontalscrollview"         android:layout_width="match_parent"         android:layout_height="@dimen/eighty_dp"         android:layout_alignparentbottom="true"         android:background="@android:color/white">          <linearlayout             android:id="@+id/thumbnails_ll"             android:layout_width="wrap_content"             android:layout_height="match_parent"             android:background="@drawable/green_square"             android:gravity="center_vertical"             android:orientation="horizontal"             android:paddingtop="2dp" />     </horizontalscrollview>       <textview         android:id="@+id/nexttxt"         android:layout_width="@dimen/ninty_dp"         android:layout_height="wrap_content"         android:layout_alignparentright="true"         android:layout_below="@+id/topbar"         android:layout_marginright="@dimen/twenty_dp"         android:layout_margintop="@dimen/twenty_dp"         android:background="@drawable/green_capsule"         android:gravity="center"         android:padding="@dimen/five_dp"         android:text="@string/next"         android:textcolor="@android:color/white"         android:textsize="@dimen/twenty_sp" /> </relativelayout>  operationalclass  public class makebackground extends basefragment implements view.onclicklistener {      imageview backgroundimage;     linearlayout flower_ll, ballon_ll, teddy_ll, textfont_ll, thumbnails_ll;     imageview flowerimage, ballonimage, teddy_image, textfontimage;     horizontalscrollview horizontalscrollview;     textview nexttxt;     int pos;     static bitmap mbitmap;     textview canceltxt;     imageview menuimage, helpimage, messageimage, funnygiftimage;      linearlayout background_ll;     int[] flowerarray = {r.drawable.flower1, r.drawable.flower2, r.drawable.flower3, r.drawable.flower4, r.drawable.flower5, r.drawable.flower6,             r.drawable.flower7, r.drawable.flower8, r.drawable.flower9, r.drawable.flower10, r.drawable.flower11, r.drawable.flower12,             r.drawable.flower13, r.drawable.flower14, r.drawable.flower15, r.drawable.flower16, r.drawable.flower17, r.drawable.flower18,             r.drawable.flower19, r.drawable.flower20, r.drawable.flower21, r.drawable.flower22, r.drawable.flower23, r.drawable.flower24,             r.drawable.flower25, r.drawable.flower26, r.drawable.flower27, r.drawable.flower28, r.drawable.flower29, r.drawable.flower30,             r.drawable.flower31, r.drawable.flower32, r.drawable.flower33};     int[] ballonarray = {r.drawable.balloon1, r.drawable.balloon2, r.drawable.balloon3, r.drawable.balloon4, r.drawable.balloon5};     int[] teddyarray = {r.drawable.teddy1, r.drawable.teddy2, r.drawable.teddy3, r.drawable.teddy4, r.drawable.teddy5, r.drawable.teddy6             , r.drawable.teddy7, r.drawable.teddy8, r.drawable.teddy9, r.drawable.teddy10, r.drawable.teddy11, r.drawable.teddy12, r.drawable.teddy13};      int[] imagearray;      public static makebackground newinstance(bitmap b) {         mbitmap = b;         return new makebackground();     }      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         bundle b = this.getarguments();         if (b != null) {             pos = b.getint("value");         }     }      @nullable     @override     public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) {         view v = inflater.inflate(r.layout.background_dragn_drop, null);         return v;     }      @override     public void onviewcreated(view view, @nullable bundle savedinstancestate) {         super.onviewcreated(view, savedinstancestate);          selectbackground sb = appdelegate.getinstance().getsblist().get(pos);          canceltxt = (textview) view.findviewbyid(r.id.canceltxt);          menuimage = (imageview) view.findviewbyid(r.id.menuimage);         helpimage = (imageview) view.findviewbyid(r.id.helpimage);         messageimage = (imageview) view.findviewbyid(r.id.messageimage);          backgroundimage = (imageview) view.findviewbyid(r.id.backgroundimage);          flower_ll = (linearlayout) view.findviewbyid(r.id.flower_ll);         ballon_ll = (linearlayout) view.findviewbyid(r.id.ballon_ll);         teddy_ll = (linearlayout) view.findviewbyid(r.id.teddy_ll);         textfont_ll = (linearlayout) view.findviewbyid(r.id.textfont_ll);         thumbnails_ll = (linearlayout) view.findviewbyid(r.id.thumbnails_ll);          background_ll = (linearlayout) view.findviewbyid(r.id.background_ll);          flowerimage = (imageview) view.findviewbyid(r.id.flowerimage);         ballonimage = (imageview) view.findviewbyid(r.id.ballonimage);         teddy_image = (imageview) view.findviewbyid(r.id.teddy_image);         textfontimage = (imageview) view.findviewbyid(r.id.textfontimage);          nexttxt = (textview) view.findviewbyid(r.id.nexttxt);          horizontalscrollview = (horizontalscrollview) view.findviewbyid(r.id.horizontalscrollview);          menuimage.setbackgroundresource(r.drawable.ic_arrow_back);          menuimage.setvisibility(view.visible);         helpimage.setvisibility(view.visible);         messageimage.setvisibility(view.visible);         canceltxt.setvisibility(view.visible);          menuimage.setonclicklistener(this);         helpimage.setonclicklistener(this);         messageimage.setonclicklistener(this);           flower_ll.setonclicklistener(this);         ballon_ll.setonclicklistener(this);         teddy_ll.setonclicklistener(this);         textfont_ll.setonclicklistener(this);          if (mbitmap != null)             backgroundimage.setimagebitmap(mbitmap);         else {             drawable drawable = getresources().getdrawable(sb.getdrawableid());             backgroundimage.setimagedrawable(drawable);         }          flower_ll.setbackgroundcolor(getresources().getcolor(r.color.green));         flowerimage.setbackgroundresource(r.drawable.flower_n);         flower_ll.setbackgroundresource(r.drawable.green_square);         ballon_ll.setbackgroundresource(r.drawable.green_square);         teddy_ll.setbackgroundresource(r.drawable.green_square);         textfont_ll.setbackgroundresource(r.drawable.green_square);          flower_ll.setbackgroundcolor(getresources().getcolor(r.color.green));         ballon_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));         teddy_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));         textfont_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));          flowerimage.setbackgroundresource(r.drawable.flower_n);         ballonimage.setbackgroundresource(r.drawable.balloon_g);         teddy_image.setbackgroundresource(r.drawable.teddy_g);         textfontimage.setbackgroundresource(r.drawable.text_g);         thumbnails_ll.removeallviews();         fillgallery(flowerarray);          horizontalscrollview.setonclicklistener(new view.onclicklistener() {            @override            public void onclick(view view) {             }        });     }      @override     public void onclick(view view) {         int id = view.getid();         if (id == r.id.flower_ll) {              performanimation(view);              flower_ll.setbackgroundresource(r.drawable.green_square);             ballon_ll.setbackgroundresource(r.drawable.green_square);             teddy_ll.setbackgroundresource(r.drawable.green_square);             textfont_ll.setbackgroundresource(r.drawable.green_square);              flower_ll.setbackgroundcolor(getresources().getcolor(r.color.green));             ballon_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));             teddy_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));             textfont_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));              flowerimage.setbackgroundresource(r.drawable.flower_n);             ballonimage.setbackgroundresource(r.drawable.balloon_g);             teddy_image.setbackgroundresource(r.drawable.teddy_g);             textfontimage.setbackgroundresource(r.drawable.text_g);              thumbnails_ll.removeallviews();             fillgallery(flowerarray);          } else if (id == r.id.ballon_ll) {              performanimation(view);              flower_ll.setbackgroundresource(r.drawable.green_square);             ballon_ll.setbackgroundresource(r.drawable.green_square);             teddy_ll.setbackgroundresource(r.drawable.green_square);             textfont_ll.setbackgroundresource(r.drawable.green_square);              ballon_ll.setbackgroundcolor(getresources().getcolor(r.color.green));             flower_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));             teddy_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));             textfont_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));              flowerimage.setbackgroundresource(r.drawable.flower_g);             ballonimage.setbackgroundresource(r.drawable.balloon_n);             teddy_image.setbackgroundresource(r.drawable.teddy_g);             textfontimage.setbackgroundresource(r.drawable.text_g);              thumbnails_ll.removeallviews();             fillgallery(ballonarray);          } else if (id == r.id.teddy_ll) {              performanimation(view);              flower_ll.setbackgroundresource(r.drawable.green_square);             ballon_ll.setbackgroundresource(r.drawable.green_square);             teddy_ll.setbackgroundresource(r.drawable.green_square);             textfont_ll.setbackgroundresource(r.drawable.green_square);              teddy_ll.setbackgroundcolor(getresources().getcolor(r.color.green));             flower_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));             ballon_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));             textfont_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));              flowerimage.setbackgroundresource(r.drawable.flower_g);             ballonimage.setbackgroundresource(r.drawable.balloon_g);             teddy_image.setbackgroundresource(r.drawable.teddy_n);             textfontimage.setbackgroundresource(r.drawable.text_g);              thumbnails_ll.removeallviews();             fillgallery(teddyarray);          } else if (id == r.id.textfont_ll) {             performanimation(view);              flower_ll.setbackgroundresource(r.drawable.green_square);             ballon_ll.setbackgroundresource(r.drawable.green_square);             teddy_ll.setbackgroundresource(r.drawable.green_square);             textfont_ll.setbackgroundresource(r.drawable.green_square);              textfont_ll.setbackgroundcolor(getresources().getcolor(r.color.green));             flower_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));             ballon_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));             teddy_ll.setbackgroundcolor(getresources().getcolor(android.r.color.white));              flowerimage.setbackgroundresource(r.drawable.flower_g);             ballonimage.setbackgroundresource(r.drawable.balloon_g);             teddy_image.setbackgroundresource(r.drawable.teddy_g);             textfontimage.setbackgroundresource(r.drawable.text_n);              utility.replacefragment(((mainactivity) getactivity()), new colorpicker());         } else if (id == r.id.menuimage) {             performanimation(view);             ((mainactivity) getactivity()).changetobackarrow();             ((mainactivity) getactivity()).onmenupressed();         } else if (id == r.id.helpimage) {             performanimation(view);             if (utility.isconnectedfast(getcontext())) {                 ((mainactivity) getactivity()).onhelpbuttonpressed();             } else {                 if (new savedata(getcontext()).isitalian())                     showtoast(getresources().getstring(r.string.internet_italy));                 else                     showtoast(getresources().getstring(r.string.internet));             }         } else if (id == r.id.messageimage) {             performanimation(view);             if (utility.isconnectedfast(getcontext())) {                 ((mainactivity) getactivity()).onmessagebuttonpressed();             } else {                 if (new savedata(getcontext()).isitalian())                     showtoast(getresources().getstring(r.string.internet_italy));                 else                     showtoast(getresources().getstring(r.string.internet));             }         }     }      public void fillgallery(int[] imagearray) {         this.imagearray = imagearray;         background_ll.removeallviews();          (int = 0; < imagearray.length; i++) {             final imageview imageview = new imageview(getactivity());             imageview.setid((integer.valueof(100 + i)));             imageview.setpadding(2, 2, 2, 2);             imageview.setimagebitmap(bitmapfactory.decoderesource(getresources(), imagearray[i]));             imageview.setscaletype(imageview.scaletype.center_inside);             imageview.setbackgroundresource(r.drawable.green_square);             thumbnails_ll.addview(imageview);              thumbnails_ll.settag(i);         }      } } 

result image


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -