I solved it, the parameter must be: getPackageName()+":drawable/"+symbolIdentifier
Still the question: How can it be done better? Thanks, Tommaso On 17 Mrz., 11:44, Tommaso <[email protected]> wrote: > Hi all, > > in my application I have a table that stores information for symbols. > These symbols have to be displayed, so also the source, the *.png, is > stored in each row. These symbols are loaded randomly at runtime. > > How do I get the the image(s) to be loaded? > > getResources().getIdentifier(symbolIdentifier, null, null) always > results 0 (zero). > > Here is the code: > private void loadSymbol(final String source) { > int imageIdentifier = getResources().getIdentifier > (symbolIdentifier, null, null); > Bitmap bitmap = BitmapFactory.decodeResource(getResources(), > imageIdentifier); > mImageOfSymbol.setImageBitmap(bitmap); > mImageOfSymbol.setVisibility(ImageView.VISIBLE); > mImageOfSymbol.refreshDrawableState(); > } > > It says in the JavaDoc that the use of getIdentifier() is discouraged. > What is a best practice to load images at runtime, when only knowing > the source as a string? > > Many thanks in advance. > > Ciao, > Tommaso --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

