Reputation: 679
I got an adapter
and I got an action which open a "app camera", then I capture the image. And from here it got to execute a function called onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
, but I can't override
the method because I can't extend AppCompatActivity().
Any help?
Upvotes: 0
Views: 817
Reputation: 10517
You can't, in Java classes can't inherit from two classes at the same time. Only one. Considering your adapter already extends RecyclerView.Adapter
then you can't.
The recommended approach is to use callback. A callback is an interface
that is implements
on the host activity or fragment and pass as an argument to the other class (the adapter on this case). Your adapter will hold a reference to the callback, so when the view is clicked then the reference will be called triggering the implementation on the activity or fragment.
You can see a detailed explanation here
onActivityResult
on the activity pass the result to the adapterpublic void addPhoto(SomeObject object){
yourData.add(object);
notifyDataseChanged();
}
onActivityResult
should be something like thisSomeObject objet = data... //you have to get the data and transform it to your format
adaper.addPhoto(object)
Upvotes: 1