I am Trying to do something similar to this and I have Problems, too. I am using dynamic ImageViews on my Screen. Per OnClickListener I am changing the Resource ID's of the Views.
I want to be able to tell what the Resource ID of the Drawable shown in the View that was clicked is.
OnClickListener(View v)
{
ImageView temp=(ImageView)v;
//I Can change Image Resource of the Clicked View with this->
temp.setImageResource(R.drawable.picture_1);
//but how can I find out what Resource ID the Drawable has that is displayed in the View?
//(I'm searching for a method ->temp.getImageResource();)
}
Thanks for your help! Philipp
Something like this should work
temp.setImageResource(R.drawable.picture_1);
temp.setTag(R.drawable.picture_1);
and then to get the resource id
temp.getTag();
Related
How do I assign an id to a drawable in text view in the xml file.
The three dots is the drawable.
So I can find it by id.
findViewById<??????>(R.id.id_of_drawable)
I used an image view next to the text view.
android:srcCompat made the image invisible.
When I changed it to android:src it worked.
I am trying to display image from changing url in my code to image view. How can I convert my resource id for image view in layout to ImageView object. there is no findViewById in app widgets and RemoteViews has setImageViewResource but it accepts drawables only and not the id's in layout xml. Guys, please please help..
ImageView logoView = new ImageView();
logoView.setImageResource(R.id.merchant_image);//this is error as this id is not in drawable but in layout.
Please please guide..
Change
ImageView logoView = new ImageView();
to
ImageView logoView = (ImageView)getView()findViewById(R.id.merchant_image);
Edit :
for your warning “Class loader may fail for processes that host multiple applications”
try
Android: "Class loader may fail for processes that host multiple applications"
I created a custom listview for installed apps. The listview contains icon and text. Now my problem is how to get/retrieve the BitmapDrawable icon from the customised listview when onListItemClick?
The icons in the custom listview is from:
static ArrayList<BitmapDrawable> Iconlist= new ArrayList<BitmapDrawable>();.
Inside onListItemClick I used:
SelectedIcon=(BitmapDrawable) Iconlist.get(position);
to get the icon, but its not working.
Please help me.
As #Rakesh Bhalani says, you should use the view returned by onListItemClick as argument, casting the view for an ImageView:
ImageView imageView = (ImageView)view.findViewById(id_of_your_icon);
then extract the drawable from the ImageView, casting as BitmapDrawable:
BitmapDrawable drawable = (BitmapDrawable)imageView.getDrawable();
In onItemClick listener of ListView you will get clicked 'view' as an argument, you should use view.findViewById(id_of_your_icon) to get the icon.
I have a custom listview.In that I want to get ids of widgets used in particular row.Because I want to set the values on a textview click ,which is present in same xml.
How to get element ids of particular row
thanks
See answer at: How to get widget ids of selected row of listview
As you want to get hold of the textview in the same row, you can do the following.
with the textview that was clicked get its parent and then using the parentview you can search for your textview:
View parent = (View) textViewThatWasClicked.getParent();
if (parent != null) {
TextView textViewThatYouWantToChange = parent.findViewById(R.id.textViewThatYouWantToChange);
textViewThatYouWantToChange.setText(...);
}
you will need to change the id that you look for to the id you have for that other textview. If you need to set an id you can do this in the xml layout file you used.
I cant follow your code well enough to actually give you the code but this should be enough to get you in the right direction.
I have a reference to an activity, but I don't know the ID of content view for the activity.
I need to find all the views in the layout.
Can I get the ID of the layout of an activity programmatically at runtime.
I'm not sure if you can get layout id but you ca try with
activity.getWindow().getDecorView().getRootView()
and from here you can get any child view you want
Probably, I don't understand your question, but I think you may get views by there ID using:
View v = activity.findViewByID(required ID)