The question might be duplicate ..sorry for that.
I have an activity (test activity) and array adapter (test array) for same.
The list contains image and text. but the image is not displayed always. It has some condition. So look is like
---------------------------------------
image1 text1
test2
test3
image4 test4
---------------------------------------
So test activity display the above list on screen.
Now i want to do different screen load on image (image activity) and text (text activity).
As the on-click handler will be in separate file (test array) i am not sure how to return to test activity and to specific task.
actually i have a list view with image and text.
Below are some scenario
Image will not be present on each row.
If image is present then Onclick of image shown other screen (for example image activity).
if user click other than image that is text show text activity screen).
What i have done is i have a list click handler in a separate file that is ArrayAdapter so i cant't do image click listener there.
So the issue was how to identify which row image is clicked?
Solution:
After lots of R&D and code changes i done below and its working:
I have added android:onClick="ImageClickHandler" for image click in xml.
and during row creation i have set row position as Id.
So when clicked on image you can get position by view.getId(), so u have the position when u click on image and hence you can get complete data on that row.
Might be there is another way....but this is what work for me.
Related
Ok so I have a list view with a custom list view adapter, and each list item has an "icon". when I click the list item, I am easily able to get all the text field names such as name address etc.
I have their icon in an image view (obviously every icon is in the same id because it is getting reused in the listview). my question is how can i get the r.drawable.resource (ie pic1) when i click the list item . and pass it to my next intent (I know how to use bundle extras).
I have been searching and I can set the resource but cannot retrieve it from a imageview.
Passing the Image in PutExtra in Android
most answers I have seen are like the link above, and this assumes that you either have different ids for each image view or that you want to turn the image view into bytes(do not want to do that). does anyone know how to get the r.drawable from the image view?
ImageView myimage = (ImageView) view.findViewById(R.id.myrate);
When you set the imageView's drawable, you can set the ImageView's tag:
imageView.setTag(R.drawable.my_drawable);
imageView.setDrawableResource(R.drawable.my_drawable);
And later use:
imageView.getTag();
So I have been scratching my head and trying to figure out how to do it.
TO give some more info:
I have a gridview with a bunch of pictures taken from a database. When someone clicks a picture, a new activity starts and there is an imageview that shows that same picture that was clicked. The above I have already coded except for the button that can change the imageview.
Now I would like to implement a button that basically shows the next picture from the database (or the next picture to the right from the gridview).
I am looking for a button that when pressed, will switch the imageview to display a different image from my database.
I have tried to use imageswitcher, viewswitcher, and some other things but to no avail.
I have a function called "GetPic" that takes the path of the pic (from drawable) clicked so it can show it in the imageview in the new activity.
if any other info is needed, i'll gladly share it.
thanks!
EDIT: getpic is my function that grabs the drawble path from the database. If I put (GetPic(activity_here.pos)) activity_here.pos will give GetPic the position from the gridview (which picture was selected) and then GetPic spits out the path the the picture selected so it can be shown in the imageview
if I do (GetPic(activity_here.pos+1)) this will show the next picture (which is what I want) just if I make the button simply add one to the position, I have to turn my imageview in to "final" so I can only get the next picture once(i don't want), not until I have run out of pictures to show(i want).
Check this : Android: ImageSwitcher
Also this would help you as well: https://www.youtube.com/watch?v=Jc11oWIjz-w
& don't forget the third part. Good luck .
I have a listview which has as image and a text.
Bases on conditions i have set two different images for the text views.
To set the images i have used
viewholder.btnFavItem.setImageResource(R.drawable.imagA);
Now on click i want toggle the images. if initially it was image a, i want it to becomes image b.
I have used the onclick listner and not the on item click becoz i need the position of image and the textview.I need the position becoz the textview can have either of the two images.the one that has image a,i want to change that to image b. i am clicking on the image and not the tetxview. i have used a custom adapter which extends base adapter.
in the onclick i am again using
viewholder.btnFavItem.setImageResource(R.drawable.imagB);
In the xml i have used clickable as true and focusable as false.
how do i toggle these images.
What you can actually do is use a tag to your image via setTag(), and compare it with your getTag():
String tag = viewholder.btnFavItem.getTag();if(tag.equals("imagA")){ viewholder.btnFavItem.setImageResource(R.drawable.imagB); viewholder.btnFavItem.setTag("imagB");}else if(tag.equals("imagB")){ viewholder.btnFavItem.setImageResource(R.drawable.imagA); viewholder.btnFavItem.setTag("imagA");}
Hello I have a listview set up with an icon to the left of each row using a row.xml. When the activity is started i would like to have one icon but when a the menu is opened and an item there is selected i want to change the icon in just one position. For example
I Cat
I Dog
I Mouse
I Food
Where I is my icon and the rest then the rest is my list i would like to change just the I in the second position so that the list would look like this
I Cat
D Dog
I Mouse
I Food
So some how get all the positions and then do like
for (position 1){
change the imageview
}
But i still want the first listview to be the default how can i change the icon of just one row? Thank you for any help
What's your underlying data structure that you're binding to? If it's a Cursor you could call notifyChange on a Content resolver to let the adapter know the data has been updated.
Ended up doing this
ImageView imageView = (ImageView) lView.getChildAt(position).findViewById(R.id.checkbox);
imageView.setImageResource(R.drawable.checkbox);
While working over listView I have came across a trouble situation.
Actually I am having a image view defined in layout that is to be inflated,
And I am doing so by adapter with my own bean class XYZ.
Now what I want is I'm checking the variable pic of the bean.
If no image there ,the image view is to be hidden or gone,
When the "pic" is available it should show the list,
But the ListView getView is called everytime I scroll,,, The image appear and disappear abruptly on list scroll,
Please help me put of the situation.
I want ImageView to be displayed when it is available. And hide it when pic tag is " " (empty)
You should create a transparent image and put it in dise the drawable folder
add a condition in side the getView method
if (tag==----)
ImageView.setImageDrawable(R.Id.TransparentImage)
else
ImageView.setImageDrawable(R.Id.AvailablkeImage)
it is appear like as image is hidden in list view.
I hope this is help.