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
32
votes
6 answers

How to properly handle screen rotation with a ViewPager and nested fragments?

I've got this activity, which holds a fragment. This fragment layout consists of a view pager with several fragments (two, actually). When the view pager is created, its adapter is created, getItem gets called and my sub fragments are created.…
Benoit Duffez
  • 9,889
  • 11
  • 69
  • 114
32
votes
4 answers

Using Android AutoCompleteTextView with ArrayAdapter instead of ArrayAdapter

I wanted to use AutoCompleteTextView in my android application.I know how to use it with simple array of Strings, but I wanted AutoCompleteTextView to use list of Objects to perform completion.My code for this is following: ACTIVITY CODE public…
Anshul
  • 7,476
  • 10
  • 39
  • 61
31
votes
4 answers

RecyclerView.Adapter.notifyItemChanged() never passes payload to onBindViewHolder()

I'm trying to update a ViewHolder in a RecyclerView without rebinding the entire thing. According to the docs, I should do this by calling RecyclerView.Adapter.notifyItemChanged(int position, Object payload), where payload is an arbitrary object…
30
votes
8 answers

RecyclerView Adapter notifyDataSetChanged not working

I extended RecyclerView.Adapter And when I called: mRecyclerView.getAdapter().notifyDataSetChanged(); Nothing happened. The only way to refresh the view is to set again the adapter (see this…
David
  • 34,355
  • 30
  • 113
  • 139
30
votes
3 answers

How do I access to ListView from the adapter

I have a custom ListView with my own adapter. I'm handling the click on a Button in my ListView's item, and I want the ListView to become invisible on this click. I have no idea how to get access to the ListView from the adapter. public class…
user1049280
  • 4,946
  • 8
  • 31
  • 51
29
votes
2 answers

RecyclerView.ViewHolder unable to bind view with ButterKnife

I'm using ButterKnife to bind my views on my ViewHolder. My code is below: public class MyAdapter extends RecyclerView.Adapter { private List data; public MyAdapter(List data) { …
KVISH
  • 12,097
  • 15
  • 79
  • 151
27
votes
6 answers

Does notifydatasetchanged call onCreateViewHolder when using RecyclerView

I want to use a toggle to toggle between two different views but using the same RecyclerView. Basically, once you toggle, I want the RecyclerView adapter to recall onCreateViewHolder() but this time it will use a different layout item file. Does…
27
votes
2 answers

RecyclerView onBindViewHolder only called when getItemViewType changes

I have a viewholder with multiple viewtypes. When scrolling onBindViewHolder is only called when getItemViewType changes value. This causes my list items to not be updated properly. Is this a bug? Or I'm i doing something wrong here. This seems very…
26
votes
3 answers

ListView or TableLayout?

I am really confused now as to which one to learn. I am an iPhone app developer and now learning Android development. I have learnt how to use a ListView with a static array of strings using an Adapter. I am used to using custom cells in iPhone,…
24
votes
3 answers

Use custom View in a RecyclerView Adapter?

I have a basic custom View which looks like this: public class CustomView extends RelativeLayout { private User user; private ImageView profilePicture; public CustomView(Context context) { super(context); init(); …
23
votes
1 answer

Android Data Binding : Observable List to RecyclerView's Adapter

Is their a way, by using the ObservableList class from the new Data Binding library and the MVVM pattern, to avoid using "notifyItem(s)..." methods from the Adapter class? Or if not what could be the simpliest way to bind an ObservableList to a…
MHogge
  • 4,504
  • 12
  • 45
  • 86
22
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
  • 1,810
  • 14
  • 42
22
votes
2 answers

Android: Radio button in custom list view

I am developing an application in which I need to implement radio buttons in list view. I want to implement a list view having one radio button and two text views in each row. And one button "Ok" below listview. What I have done is created a list…
21
votes
3 answers

Dynamically change the number of columns of a GridLayoutManager

I am actually using a GridLayoutManager with two columns in my app and I would like to have one column depending on the view type used. Here is the code I have in the method "onCreateView()" of my fragment : // Recycler view for users usersList =…
fraxool
  • 2,955
  • 4
  • 25
  • 54
21
votes
2 answers

Explanation of the getView() method of an ArrayAdapter

Could you explain the getView() method of an ArrayAdapter. I read the docs and it has three parameters: position: The position of the item within the adapter's data set of the item whose view we want. convertView: The old view to reuse, if…