Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I am a beginner in android studio.
In an application there is five horizontal rows. In any row there are ten pics and properties of the pic. Click on any pic put extra to intent and direct to another activity.
How can I write onclick event for all pics?
Should I write 50 onclick events for all pics?
Is there any other way?
Thanks

What I have tried:

Same click function for any pic in android studio
Posted
Updated 3-Apr-17 23:06pm
Comments
Mohibur Rashid 4-Apr-17 3:22am    
try this
http://stackoverflow.com/questions/5990255/android-how-to-write-click-event-of-an-imageview

1 solution

I'd write a method in the Activity, say

Java
public void onImageClick(View view) {
    ImageView image = (ImageView)view;
    // ... do your stuff with the image, add your extra to intent, etc etc
}


and in the xml design I'd simply put

XML
android:onClick="onImageClick"


in every ImageView.

Of course, this can be optimized (creating a xml-design containing a fully formatted imageview the way you need it and simply <include> that imageview 50 times or derive your own ImageView etc, but as you said, you are a beginner in Android Studio, I'd go for the most simple approach here so you keep control of what's happening.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900