8

I have a recycler view adapter. So it hosts 3 views. Simply each view has ImageView. When a user clicks on image (1 out of 3) It creates new intent to use a photo app and returns it to caller when done. The caller (the activity, which created RecyclerView and its adapter) handles onActivityResult. From there I need to set a thumbnail image that was taken in that mentioned intent to the corresponding selected ImageView.

Question. In my Activity, how do I know which imageView (out of available 3) to modify ? My Activity knows only a position of which item in recycler view adapter clicked on.

Is it possible to somehow get a reference to a particular imageView in the adapter by only using position? So something like this: from activity: adapter.getImageView(position)

EDIT: So my solution was: I was keeping track of all ImageViews in the adapter and stored their ref in ArrayList in the `onBindViewHolder. so now I can just use adapter.getImageView(position)

vankiz
  • 106
  • 1
  • 6
  • How are you assigning values to each item on ur adapter? I'm gonna assume you using an arraylist right? If so, can't you try referencing the index of the arraylist with the adapter position? It works for me – spongyboss Jul 11 '15 at 00:51
  • I need to access a particular view, not a value. – vankiz Jul 11 '15 at 00:52
  • The thing is, the only way to use photo app to capture image is to create intent, no way to handle back the response in the actual adapter. I need to access a particular ImageView in my adapter.... or I guess in each onBindViewHolder I should just keep track of ImageViews in array list.. hmmm – vankiz Jul 11 '15 at 00:54
  • Yeah, that's an idea.. I just reread your question properly... try using an arraylist! I had a similar issue few months back, I believe an array list solved it for me – spongyboss Jul 11 '15 at 00:57

2 Answers2

-1

I believe you can setOnClickListener for your ImageView (or for your row View) in the adapter. Just fire intent from there.

Kise
  • 2,823
  • 1
  • 24
  • 43
  • 1
    Yes I am already doing that. But to receive response, I have to do it in the activity/fragment, which is outside of the adapter. Then from the Activity/fragment I need to get to the right ImageView in my adapter. I am using ArrayList right now and it seems to be working. – vankiz Jul 11 '15 at 01:18
  • yeah, if the data set of your adapter is ImageView then it may work out well in the end. I did have a similar problem to yours, and had to create a static instance of `onActivityResult` in both my adapter and activity to solve it. – Kise Jul 11 '15 at 01:24
  • no atempts to demostrate your view, very lazy answer – Gustavo Baiocchi Costa Feb 15 '17 at 15:41
-1

Simply Add method to adapter to return reference to image at desired position Adapter holds list of objects u pass to it so u can manipulate them as you desired

ceph3us
  • 7,326
  • 3
  • 36
  • 43