Image display

Put your problem here if it does not fit any of the other categories.

Image display

Postby thanu » Mon Mar 10, 2008 6:21 am

Hello plusminus.........

thanks for that code.......I tried that ,but still not getting output......can u please guide me.I will attach my code .......I can execute that code without any bug but it will out put only the two strings that we have have added in the xml code........


//here is the code//

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.google.photo;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.os.Bundle;
  8.  
  9.  
  10.  
  11. public class photo extends Activity {
  12.  
  13.     /** Called when the activity is first created. */
  14.  
  15.     @Override
  16.  
  17.     public void onCreate(Bundle icicle) {
  18.  
  19.         super.onCreate(icicle);
  20.  
  21.         setContentView(R.layout.main);
  22.  
  23.         getAllResourceIDs(R.drawable.class);
  24.  
  25.     }
  26.  
  27.  
  28.  
  29.                 private int[] getAllResourceIDs(Class<R.drawable> aClass) throws IllegalArgumentException{
  30.  
  31.             /* Get all Fields from the class passed. */
  32.  
  33.             java.lang.reflect.Field[] IDFields = aClass.getFields();
  34.  
  35.  
  36.  
  37.             /* int-Array capable of storing all ids. */
  38.  
  39.             int[] IDs = new int[IDFields.length];
  40.  
  41.  
  42.  
  43.             try {
  44.  
  45.                  /* Loop through all Fields and store id to array. */
  46.  
  47.                  for(int i = 0; i < IDFields.length; i++){
  48.  
  49.                       /* All fields within the subclasses of R
  50.  
  51.                        * are Integers, so we need no type-check here. */
  52.  
  53.                        
  54.  
  55.                       // pass 'null' because class is static
  56.  
  57.                       IDs[i] = IDFields[i].getInt(null);
  58.  
  59.                  }
  60.  
  61.             } catch (Exception e) {
  62.  
  63.                  /* Exception will only occur on bad class submitted. */
  64.  
  65.                  throw new IllegalArgumentException();
  66.  
  67.             }
  68.  
  69.             return IDs;
  70.  
  71.        }
  72.  
  73.  
  74.  
  75. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


//code//

thanks in advance
thanu
Freshman
Freshman
 
Posts: 3
Joined: Fri Mar 07, 2008 6:36 am

Top

Postby plusminus » Mon Mar 10, 2008 7:45 pm

Hello thanu,

you just received all the drawable IDs, but you need to do sth with them :!:

Maybe have a look at this tutorial: http://www.anddev.org/viewtopic.php?t=332

There you have a preset Array if drawable IDs:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         private int[] myImageIds = {
  2.  
  3.                R.drawable.image_1,
  4.  
  5.                R.drawable.image_2,
  6.  
  7.                R.drawable.image_3,
  8.  
  9.                R.drawable.image_4
  10.  
  11.         };
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 13 guests