android - How to make a group of clickable graphical object? -


my question how can make set of clickable images on android.

i can make 1 clickable sphere using shapedrawable, want make more 1 @ once , still able clicks in of them.

moreover want position them on screen @ will, instead of auto positioned layouts.

the number of spheres can change can places.

this code use make one:

main.java

package com.teste;  import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.linearlayout; import android.widget.toast;  public class main extends activity {     /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          linearlayout layout = new linearlayout(this);          customdrawableview mcustomdrawableview = new customdrawableview(this, 100, 100, 50, 50, 0xff74ac23);         customdrawableview mcustomdrawableview2 = new customdrawableview(this, 10, 10, 50, 50, 0xffffffff);          mcustomdrawableview.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 toast.maketext(getbasecontext(), "clicked green ball", toast.length_short).show();               }         });          mcustomdrawableview2.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 toast.maketext(getbasecontext(), "clicked white ball", toast.length_short).show();               }         });          layout.addview(mcustomdrawableview);         layout.addview(mcustomdrawableview2);         setcontentview(layout);      } } 

customdrawableview.java

package com.teste;  import android.content.context; import android.graphics.canvas; import android.graphics.drawable.shapedrawable; import android.graphics.drawable.shapes.ovalshape; import android.view.view; import android.view.viewgroup.layoutparams;  public class customdrawableview extends view {     private shapedrawable mdrawable;      public customdrawableview(context context, int i, int j, int k, int l, int m) {         super(context);          layoutparams params = new layoutparams(layoutparams.fill_parent, layoutparams.fill_parent);         super.setlayoutparams(params);          mdrawable = new shapedrawable(new ovalshape());         mdrawable.getpaint().setcolor(m);         mdrawable.setbounds(i, j, + k, j + l);     }      protected void ondraw(canvas canvas) {         mdrawable.draw(canvas);     } } 

hope can :)

it should easy making clas

customdrawableview extends view implements onclicklistener {     // code here      public void onclick(view v) {           // callback function here     } } 

take @ 1 example wrote time ago in answer: android onclick method doesn't work on custom view


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -