Questions tagged [adapter]

Use this tag for questions relating to the Adapter design pattern, one of the Gang of Four's structural design patterns. Also consider using the [design-patterns] tag and a programming language tag if applicable.

According to the GoF book (page 139) the purpose of the Adapter design pattern is to,

Convert the interface of a class into another interface clients expect. The adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

There are two different versions of the Adapter design pattern (page 141).

  1. A class adapter uses multiple inheritance to adapt one interface to another. 2. An object adapter relies on object composition.

There are three scenarios where the Adapter design pattern is applicable (page 140).

  1. you want to use an existing class, and its interface does not match the one you need. 2. you want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces. 3. (object adapter only) you need to use several existing subclasses, but it's unpractical to adapt their interface by subclassing every one. An object adapter can adapt the interface of its parent class.

There are different consequences of applying the Adapter design pattern depending on which version is used (page 142).

Class and object adapters have different trade-offs. A class adapter

  • adapts Adaptee to Target by committing to a concrete Adaptee class. As a consequence, a class adapter won't work when we want to adapt a class and all its subclasses.
  • lets Adapter override some of Adaptee's behavior, since Adapter is a subclass of Adaptee.
  • introduces only one object, and no additional pointer indirection is needed to get to the adaptee.

An object adapter

  • lets a single Adapter work with many Adaptees—that is, the Adaptee itself and all of its subclasses (if any). The Adapter can also add functionality to all Adaptees at once.
  • makes it harder to override Adaptee behavior. It will require subclassing Adaptee and making Adapter refer to the subclass rather than the Adaptee itself.

For details about the structure and implementation of the Adapter design pattern, see the following online resources.

Note the tag encompasses this pattern as well as the other 22 patterns from the GoF book. Consider using any of these tags in combination, as applicable.

5035 questions
1
vote
1 answer

Extend a class from an adapter class

In my application should be a lot of adapters similar to each other and I would like to know whether it is possible to make the interface or superclass to inherit from there and then, instead of writing 10 adapters, thanks !! My adapter code public…
1
vote
1 answer

Android studio not deleting my items in Adapter?

public void setSearch(ArrayList ListSearch){ search=ListSearch; removeInActiveClasses(search); notifyItemRangeChanged(0,search.size()); } public void removeInActiveClasses(ArrayList data){ for(int…
Eli
  • 827
  • 1
  • 7
  • 21
1
vote
1 answer

Child's viewpager destroyed/getting invisible after parent viewpager's page slide

I've a ViewPager (Parent ViewPager) in my activity with 4 fragments. One of the fragments implements a sliding ViewPager (Child ViewPager) with automatic sliding. When I swipe the parent ViewPager to, say, tab 3 and then I go back to the first…
Basu
  • 763
  • 8
  • 27
1
vote
1 answer

Trouble using Ember graphql-adapter and postgraphql

Ember and Graphql are both new to me and i'm trying to get my application working with Postgraphql without success I use Ember and https://github.com/alphasights/ember-graphql-adapter but the query made by ember-graphql-adapter doesn't match the…
vatourni
  • 117
  • 1
  • 6
1
vote
1 answer

how can i start view pager from a custom position and can swipe back and forth from that position?

how can i start view pager from a custom position and can swipe back and forth from that position in android? class ImageZoom extends PagerAdapter { @Override public int getCount() { return storeData.dataList.size(); //…
Salim
  • 11
  • 1
1
vote
1 answer

Adapter changing images upon fast scrolling

hey guys I've this adapter that retrieves news list populated from a web service and it is working just fine but the problem is when I scroll fast the images (of the unseen rows) are being substituted, can you help? Here's my adapter: public class…
eshteghel company
  • 471
  • 1
  • 7
  • 22
1
vote
1 answer

Android RecyclerView does not animate all the items

in my application i have made a Recyclerview with selection mode. When the user choose to start the selection mode i call notifyDataSetChanged(); and from onBindViewHolder() i call a method to animate the layout item a little bit right…
Kick
  • 21
  • 1
  • 2
1
vote
1 answer

java.lang.IllegalMonitorStateException: object not locked by thread before notify() - onResponse

I am trying to set the adapter of a RecyclerView within the onCreate(). I read that the notifyDatasetChanged() can be invoked on the main thread only. But how can this be achieved? Here is my code so far: RecyclerView…
user6456773
  • 381
  • 2
  • 10
  • 18
1
vote
0 answers

Implementing Filter function for ExpandableListView adapter

I would like to filter data in my ExpandableListView adapter, but basically I have no idea how to do that. I have watched many tutorials but, maybe I have way complicated adapter at first place. Here is my adapter: package…
Senso Hakai
  • 141
  • 1
  • 2
  • 13
1
vote
2 answers

Android - Recyclerview adapter show Images from External Storage

I want create image gallery with RecyclerView where use images from phone. I didn't find any RecyclerView adapter which fill image with File type. Is it possible?
Huseyin
  • 567
  • 6
  • 17
1
vote
1 answer

Is there a way for 2 different RecyclerViews to communicate with each other?

I have an activity that has two different recyclerviews that use two different adapters. Is there a way for the recyclerviews to communicate with each other? For example: userChoiceRecyclerView(second recyclerview) has a bunch of cardview objects…
Qube
  • 13
  • 1
  • 5
1
vote
2 answers

How can i get countries and states from JSON and populate it on Spinner

I have the JSON format of countries and states, how can i add countries in one Spinner and get corresponding state in another spinner, my JSON format of counties and state is: [ { "Country": "Afghanistan", "State": [ "Badakhshan", …
Sam
  • 45
  • 1
  • 8
1
vote
1 answer

Load customize bitmap image using picasso in android listview

I need to create and set customize bitmap image on each row of listview. I am doing that using picasso. My code inside getView of adapter is like below, @Override public View getView(final int position, View convertView, ViewGroup parent) { …
Exigente05
  • 2,161
  • 3
  • 22
  • 42
1
vote
3 answers

Recycler Adapter Not updating with updated adapter

I have a fragment_1 which has button call ADD which send user to fragment_2 to fill form with 4 5 Edit Text and on same fragment_2 user need to press Save Form to return back to fragment_1 with details filled on fragment_2 till here everything is…
Ritu
  • 518
  • 2
  • 12
  • 35
1
vote
1 answer

Horizontal RecyclerViews scrolling the same dx inside Vertical RecyclerView

I have a vertical recyclerview with a horizontal recyclerview in eatch item. when I scrollBy like 100 pixels in dx, in all visible horizontal recycler views, everything is ok, but when I scroll down, the "new" horizontal recycler views appear in dx…
xanexpt
  • 713
  • 8
  • 20