[android-developers] Re: Dynamic Image loading from Resources in ImageView
Hi Dear, i need a similar solution like R.drawable.+myVairable for my stateDrawable. i have 2 stateButtons defined in res/Drawable/statebutton1.xml and res/Drawable/statebutton2.xml now i need to use a variable for Button image like Button.setBackgroundResource(R.drawable.variablename) i have considered Alexey's solution of putting images in assets folder and using getResources().getAssets().open(path to file); but i can place stateDrawable only in Drawable. please suggest any solution On Aug 3, 11:02 am, Faisal T faisalvatak...@gmail.com wrote: Hi Dude, There is a simple method. From your activity you can directly call below code getResources().getDrawable(R.drawable.rID) it will return you the drawable object. regards, Faisal T On Aug 1, 5:55 am, DroidDude bhavy...@gmail.com wrote: Hi, I am very new to Android Development and I have a doubt regarding Image Loading in ImageView from R.drawable. Just to brief What I am trying to accomplish is :Showing a ListView with ImageView and TextView using ViewWrapper pattern. I get the Text Value for TextView from one http service and I store all the values in String Array. I have implemented my own Adapter with my own implementation of getView(). Now the issue: I have put all the images i want to show in res/drawable folder. now based on the value of text I want to pick that image from the folder and show it in the Imageview. For Example: if i get aaa as the value of TextView. I already have aaa.jpg in res/ drawable folder and I want to set that image in ImageView. I don't know how to get the handle for aaa.jpg in androind. I have tried follwoing with no luck: ImageView.setImageResource() - But it takes the rID as argument which is of type int. I cant generate R.drawable.+myVairable. ImageView.setImageDrawable(Drawable.createFromPath(PATHVariable))-But I don't know how to give the path to the image. I tried ./res/ drawable/+variable+.jpg BitmapFactory takes the similar argument for all its method. I really don't want to write any Async Image Loader based on any server based URIs as I dont have any hosting server available. Kindly help. Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Dynamic Image loading from Resources in ImageView
Thanks Alexey! It worked great! On Aug 2, 3:14 pm, Alexey Krasnoriadtsev ale...@agilefusion.com wrote: you can place your images directly under assets directory, and then use getResources().getAssets().open(path to file); On Jul 31, 1:55 pm, DroidDude bhavy...@gmail.com wrote: Hi, I am very new to Android Development and I have a doubt regarding Image Loading in ImageView from R.drawable. Just to brief What I am trying to accomplish is :Showing a ListView with ImageView and TextView using ViewWrapper pattern. I get the Text Value for TextView from one http service and I store all the values in String Array. I have implemented my own Adapter with my own implementation of getView(). Now the issue: I have put all the images i want to show in res/drawable folder. now based on the value of text I want to pick that image from the folder and show it in the Imageview. For Example: if i get aaa as the value of TextView. I already have aaa.jpg in res/ drawable folder and I want to set that image in ImageView. I don't know how to get the handle for aaa.jpg in androind. I have tried follwoing with no luck: ImageView.setImageResource() - But it takes the rID as argument which is of type int. I cant generate R.drawable.+myVairable. ImageView.setImageDrawable(Drawable.createFromPath(PATHVariable))-But I don't know how to give the path to the image. I tried ./res/ drawable/+variable+.jpg BitmapFactory takes the similar argument for all its method. I really don't want to write any Async Image Loader based on any server based URIs as I dont have any hosting server available. Kindly help. Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Dynamic Image loading from Resources in ImageView
Hi Dude, There is a simple method. From your activity you can directly call below code getResources().getDrawable(R.drawable.rID) it will return you the drawable object. regards, Faisal T On Aug 1, 5:55 am, DroidDude bhavy...@gmail.com wrote: Hi, I am very new to Android Development and I have a doubt regarding Image Loading in ImageView from R.drawable. Just to brief What I am trying to accomplish is :Showing a ListView with ImageView and TextView using ViewWrapper pattern. I get the Text Value for TextView from one http service and I store all the values in String Array. I have implemented my own Adapter with my own implementation of getView(). Now the issue: I have put all the images i want to show in res/drawable folder. now based on the value of text I want to pick that image from the folder and show it in the Imageview. For Example: if i get aaa as the value of TextView. I already have aaa.jpg in res/ drawable folder and I want to set that image in ImageView. I don't know how to get the handle for aaa.jpg in androind. I have tried follwoing with no luck: ImageView.setImageResource() - But it takes the rID as argument which is of type int. I cant generate R.drawable.+myVairable. ImageView.setImageDrawable(Drawable.createFromPath(PATHVariable))-But I don't know how to give the path to the image. I tried ./res/ drawable/+variable+.jpg BitmapFactory takes the similar argument for all its method. I really don't want to write any Async Image Loader based on any server based URIs as I dont have any hosting server available. Kindly help. Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Dynamic Image loading from Resources in ImageView
you can place your images directly under assets directory, and then use getResources().getAssets().open(path to file); On Jul 31, 1:55 pm, DroidDude bhavy...@gmail.com wrote: Hi, I am very new to Android Development and I have a doubt regarding Image Loading in ImageView from R.drawable. Just to brief What I am trying to accomplish is :Showing a ListView with ImageView and TextView using ViewWrapper pattern. I get the Text Value for TextView from one http service and I store all the values in String Array. I have implemented my own Adapter with my own implementation of getView(). Now the issue: I have put all the images i want to show in res/drawable folder. now based on the value of text I want to pick that image from the folder and show it in the Imageview. For Example: if i get aaa as the value of TextView. I already have aaa.jpg in res/ drawable folder and I want to set that image in ImageView. I don't know how to get the handle for aaa.jpg in androind. I have tried follwoing with no luck: ImageView.setImageResource() - But it takes the rID as argument which is of type int. I cant generate R.drawable.+myVairable. ImageView.setImageDrawable(Drawable.createFromPath(PATHVariable))-But I don't know how to give the path to the image. I tried ./res/ drawable/+variable+.jpg BitmapFactory takes the similar argument for all its method. I really don't want to write any Async Image Loader based on any server based URIs as I dont have any hosting server available. Kindly help. Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---