I have a custom Adapter that has a click Listener on the ListView image.
This code is inside the Adapter GetView:
holder.iconImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//code to do stuff when the image is clicked
}
My images in the listview consist of images of folders (to represent a folder) and actual images.
So if the user clicks on a folder image, I want to be able to call a method called "moveDownFolder" in ActivityA.
I'm not sure if this can be done inside of the Adapter?
[EDIT] Basically in ActivityA I have a Click Listener on the custom ListView, so if they click on the text in the custom ListView, it moves down a folder (if it is a folder).
But they can click on an image in the ListView, it opens the image in a new activity. BUT if they click on the folder icon in the listview (which is an image of course in the ImageView) - I want the code to move down a folder, instead of trying to open the image.
Yes it can be done , just make your function as follows
static public moveDownFolder()
. You need to be sure that activity is created. to call that function from Adapter just simply do :YourActivity.moveDownFolder()
I Recommending on using interface as listener.
For example:
1, create your interface:
2, Let your ActivityA to implement this Interface like this:
3, you will have to auto overide the method folderClicked it will look like this:
4, send the activity listener to the adapter with constructor like this:
5, in your adapter class your code should be like this :
If the adapter is an inner class of ActivityA, try: