Questions tagged [android-adapter]

An Adapter object acts as a bridge between an AdapterView and the underlying data for that view.

An Adapter represents the connection between a View with some kind of data source. Adapters generally come in two flavours: those representing array/list based data and those that represent Cursor based data.

  • The Adapter provides access to the data items.
  • The Adapter is also responsible for making a View for each item in the data set.

See Adapter reference for more information.

Tag Usage:

3394 questions
639
votes
43 answers

Why `PagerAdapter::notifyDataSetChanged` is not updating the View?

I'm using the ViewPager from the compatibility library. I have succussfully got it displaying several views which I can page through. However, I'm having a hard time figuring out how to update the ViewPager with a new set of Views. I've tried all…
C0deAttack
  • 24,419
  • 18
  • 73
  • 81
146
votes
13 answers

How to update/refresh specific item in RecyclerView

I'm trying to refresh specific item in RecyclerView. Story: Whenever user clicks on item, it shows AlertDialog. User can type some text by clicking ok button. I want to show this text in this item and show invisible ImageView - declared in XML and…
Ahmed Elgendy
  • 1,670
  • 2
  • 12
  • 17
141
votes
10 answers

Update data in ListFragment as part of ViewPager

I'm using the v4 compatibility ViewPager in Android. My FragmentActivity has a bunch of data which is to be displayed in different ways on different pages in my ViewPager. So far I just have 3 instances of the same ListFragment, but in the future…
134
votes
10 answers

What's the role of adapters in Android?

I want to know when, where and how adapters are used in the context of Android. The information from Android's developer documentation was insufficient for me and I'd like to get a more detailed analysis.
Robin
  • 6,879
  • 7
  • 37
  • 35
99
votes
2 answers

Is there a better way of getting a reference to the parent RecyclerView from the adapter?

I have a use case where I need a reference to the parent RecyclerView from inside the adapter, specifically inside the onBindViewHolder method. So far what I am doing is assigning it to a private class member in the onCreateViewHolder method passing…
nabir
  • 1,447
  • 2
  • 12
  • 17
77
votes
1 answer

getAdapterPosition() is deprecated

I've updated my targetSdkVersion from 28 to 30 and I've noticed that getAdapterPosition() is deprecated (I'm not sure when this happened). In the documentation, they say the following: This method is deprecated. This method is confusing when…
ClassA
  • 2,480
  • 1
  • 26
  • 57
76
votes
4 answers

Best way to update data with a RecyclerView adapter

When I have to use a classic adapter with a ListView, I update my data in the ListView like this: myAdapter.swapArray(data); public swapArray(List data) { clear(); addAll(data); notifyDataSetChanged(); } I would like to know what is…
Alex DG
  • 1,859
  • 2
  • 22
  • 34
76
votes
6 answers

android - listview get item view by position

I have listview with custom adapter (base adapter). I want to get view from listview by position. I tried mListView.getChildAt(position) , but it is not working. How can i get item view by position?
alashow
  • 2,735
  • 3
  • 21
  • 47
66
votes
1 answer

Android ListView Adapter notifyDataSetInvalidated() vs notifyDataSetChanged()

What is the difference? The android documentation doesn't have a description for notifyDataSetInvalidated(). I was thinking maybe you call that function to notify all registered listeners, but use notifyDataSetChanged() to not notify them?
Spidy
  • 39,723
  • 15
  • 65
  • 83
58
votes
6 answers

Getting the android context in an adapter

In many of the code samples that I find on the internet the context is obtained in the constructor of an adapter. This context is used to get an inflater to inflate the views in getView method. My Question is why bother getting the context in the…
Gautam
  • 7,868
  • 12
  • 64
  • 105
51
votes
2 answers

findViewById vs View Holder Pattern in ListView adapter

I always use LayoutInflater and findViewById for creating new item in thegetView method of an Adapter. But in many articles people write that findViewById is very very slow and strongly recommend to use the View Holder Pattern. Can anyone explain…
47
votes
8 answers

Android - Implementing search filter to a RecyclerView

I need to implement a search feature based on an EditText to my RecyclerView. The list must be filtered while typing. Here's the code : DisplayAdapter.java this is the adapter public class DisplayAdapter extends…
Thorvald
  • 3,424
  • 6
  • 40
  • 66
46
votes
5 answers

How to customize listview using baseadapter

I wanna create a customized ListView like this: I think that I have to use BaseAdapter but I have no idea about it.
Mohsen Bahman
  • 1,092
  • 3
  • 15
  • 27
45
votes
6 answers

FragmentPagerAdapter notifyDataSetChanged not working

I got a FragmentPagerAdapter. It's getItem method can return a fragment according to data it has from the outside. After I update the data its suppose to display I call notifyDataSetChanged and yet nothing happened. I DID override the…
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
42
votes
6 answers

Custom Adapter getView() method is not called

Here is the code of the fragment in which I am setting a custom adapter to the list. There no errors but the ListView is empty. I have implemented getCount() which returns right number of items in my ArrayList. I don't see ("Inside", "GetView") in…
Ravi
  • 4,872
  • 8
  • 35
  • 46
1
2 3
99 100