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 flavors: those that represent 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:

3159 questions
142
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…
129
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
  • 5,551
  • 7
  • 32
  • 33
124
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…
Elgendy
  • 1,450
  • 2
  • 10
  • 17
84
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,287
  • 2
  • 10
  • 17
74
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…
AlexDG
  • 1,739
  • 2
  • 18
  • 33
69
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,495
  • 3
  • 17
  • 44
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
  • 38,131
  • 15
  • 59
  • 77
57
votes
5 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,444
  • 9
  • 61
  • 102
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…
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,082
  • 3
  • 15
  • 25
41
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…
39
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,632
  • 8
  • 31
  • 45
38
votes
9 answers

Android: how to refresh ListView contents?

My ListView is using an extension of BaseAdapter, I can not get it to refresh properly. When I refresh, it appears that the old data draws on top of the new data, until a scroll event happens. The old rows draw on top of the new rows, but the old…
ab11
  • 18,490
  • 37
  • 104
  • 194
37
votes
5 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…
34
votes
2 answers

How to add section separators / dividers to a ListView?

I'm currently making a menu for my app, using a DrawerLayout and an ArrayAdapter subclass to achieve something looking like Facebook's drawer menu. I currently have no problems creating the list, but now that it looks good, i'd like to add…
Jivay
  • 1,014
  • 3
  • 10
  • 23
1
2 3
99 100