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

Fragment no longer exists for key FragmentStateAdapter with Viewpager2

I am using ViewPager2 for my project. I need to use nested fragments inside a fragment with viewpager2. it works like charm until I try to navigate between fragments(not nested ones). After the first time navigating between fragments, the…
22
votes
14 answers

Fast taps (clicks) on RecyclerView opens multiple Fragments

I have implemented onClick listener to my ViewHolder for my RecyclerView But when I perform very fast double taps or mouse clicks, it performs the task (opens a seperate fragment in this case) twice or three times. here is my code public class…
22
votes
1 answer

android notifyItemRangeInserted disable autoscroll

I'm using RecyclerView as the base for my data list. i've implemented custom RecyclerView.Adapter which is based on ArraList. on fetching data from the internet the code that i'm running is: public void addItems(List items){ final int…
royB
  • 12,779
  • 15
  • 58
  • 80
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
  • 3,199
  • 4
  • 31
  • 57
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…
20
votes
4 answers

Make last Item / ViewHolder in RecyclerView fill rest of the screen or have a min height

I'm struggeling with the RecyclerView. I use a recycler view to display the details of my model class. //My model class MyModel { String name; Double latitude; Double longitude; Boolean isOnline; ... } Since some of the values…
xxtesaxx
  • 6,175
  • 2
  • 31
  • 50
19
votes
3 answers

PagedListAdapter jumps to beginning of the list on receiving new PagedList

I'm using Paging Library to load data from network using ItemKeyedDataSource. After fetching items user can edit them, this updates are done inside in Memory cache (no database like Room is used). Now since the PagedList itself cannot be updated…
19
votes
1 answer

Bluetooth device discovery in Android -- startDiscovery()

Goal: Build an Android app that discovers the names and addresses of BT devices within range and submits their values to a webservice. BT devices have not been previously bonded to the host device, I just want to poll everything as I walk…
16
votes
2 answers

Listview not getting populated, getView() isn't getting called

I'm having a few problems getting my listview to show up in a simple application i'm writing. For some reason the getView() method of my adapter class isn't getting called. However, when when getCount() is called in my adapter class it isn't…
slayton
  • 20,123
  • 10
  • 60
  • 89
15
votes
6 answers

Using AsyncTask to load Images in ListView

I have one ListView which can hold an image. It depends if image exists or not in SDCARD. Here my example code: public class MainActivity extends Activity { ListView mListView; @Override protected void onCreate(Bundle…
Rodrigo
  • 5,435
  • 5
  • 42
  • 78
15
votes
2 answers

Are android adapters an example of Adapter Design pattern?

Do Android adapters use Adapter Design pattern? The GoF design patterns book describes Adapter Design Pattern as The Adapter Pattern converts the interface of a class into another interface the clients expect. Adapter lets classes work…
uptoNoGood
  • 566
  • 5
  • 20
15
votes
3 answers

How to set two adapters to one RecyclerView?

I am developing an android app in which I'm storing two different types of information on 'FirebaseDatabase`. Then in the MainActivity, I'm retrieving them and showing to users in a RecyclerView. Both information are meant to be shown in different…
15
votes
6 answers

RecyclerView.Adapter.notifyItemMoved(0,1) scrolls screen

I have a RecyclerView managed by a LinearlayoutManager, if I swap item 1 with 0 and then call mAdapter.notifyItemMoved(0,1), the moving animation causes the screen to scroll. How can I prevent it?
Ari
  • 3,086
  • 1
  • 19
  • 27
15
votes
2 answers

CursorAdapter bindView optimization

When overriding ArrayAdapter I know is correct using a pattern like this: if(view != null){ ...create new view setting fields from data }else return view; //reuse view is correct too using this pattern with CursorAdapters? My problem is that…
user1610075
  • 1,583
  • 3
  • 15
  • 32
15
votes
1 answer

Insert pages in the middle of a FragmentPageAdapter

I'm using a ViewPager from ViewPageIndicator and I need to be able to dynamically insert one fragment in the middle of others. I've tried to manage the model with FragmentPagerAdapter and FragmentStatePagerAdapter (both from v4 support code) and the…
lujop
  • 13,504
  • 9
  • 62
  • 95