android - How to generate dynamic imageviews by using a string array -
I want to set a bitmap for two images generated from multiple image URLs and set the onteouchlistener / onclicklistener for the last image view You can do the bitmap image dynamically. Can anyone give me some suggestions to do this?
Here I am only using im0 (imageview), but I dynamically load images im0, im1 and im2 (image view) respectively. And the last imageView only to set the onclicklistener
My mainActivity is: -
Public Sphere MainActivity Spread Activity {@TargetApi (Creation.VERSION_CODES.GINGERBREAD) @Override Protected Zero on Crate (Bundle Saved Instantstate) {Super.Nuke (Saved Instance State); SetContentView (R.layout.activity_main); Array list = new arreelist & lt; String & gt; (); Im0 = (ImageView) findViewById (R.id.imageView1); Im1 = (ImageView) findViewById (R.id.imageView2); Im2 = (ImageView) findViewById (R.id.imageView3); StrictMode.ThreadPolicy Policy = New StrictMode.ThreadPolicy.Builder (). PermitAll () Build (); StrictMode.setThreadPolicy (policy); Jsonobj = JSONfunctions .getJSONfromURL ("http://192.168.1.195/Madhu/anrdmulti/multidocretrieve.php"); Try {jsonarr = jsonobj.getJSONArray ("Upload Images"); (Int i = 0; i & lt; jsonarr.length (); i ++) for {JSONObject jsonobj1 = jsonarr.getJSONObject (i); Id = jsonobj1.getInt ("id"); JSONObject jsobj = jsonobj1.getJSONObject ("All Pictures"); For (int j = 0; j & lt; jsobj.length (); j ++) {JSONArray image_array = jsobj.getJSONArray ("picture"); For (int k = 0; k & lt; image_array.length (); k ++) {string image = image_array.getString (k); Arraylist.add (image); }}}} Hold (JasonX Express E) {e.printStackTrace (); } Allimagesarr = arraylist.toArray (new string [arraylist.size ()]); For (Int j = 0; j and lt; 3; j ++) {Dryable S = load image FOB operation (submissions RR [J]); Im0.setImageDrawable (s); }} @ Override Public Boolean On Crate Option Menu (Menu Menu) {// Increase Menu; It adds the item to the Action Bar if it exists GetMenuInflater (). Fluo (R. menu menu, menu); Back true; } Public static drivel load imagefom web operation (string url) {try {InputStream = (InputStream) New URL (URL) GetContent (); Drawable d = Drawable.createFromStream (is, "src name"); Return D; } Hold (exception e) {return tap; }}
}
My xml file is: -
& lt; LinearLayout xmlns: android = "http: // schema Android / APK / race / Android" XMLN: Tools = "http://schemas.android.com/tools" Android: layout_width = "match_perrent" android: layout_hett = "match_perrent" Android: Orientation = "Vertical" & gt; & Lt; ImageView Android: id = "@ + id / imageView2" android: layout_width = "wrap_content" android: layout_height = "100dp" Android: layout_marginTop = "5dp" Android: src = "@ drawable / ic_launcher" /> & Lt; Android: layout_height = "100dp" Android: layout_marginTop = "5dp" Android: src = "@ drawable / ic_launcher" /> & Lt; Android: layout_width = "wrap_content" android: layout_height = "100dp" Android: layout_marginTop = "5dp" Android: src = "@ drawable / ic_launcher" / & gt; imageView Android: id = "@ + id / imageView3"
Comments
Post a Comment