Best way to update data with a RecyclerView adapter [duplicate]

RecyclerView’s Adapter doesn’t come with many methods otherwise available in ListView’s adapter. But your swap can be implemented quite simply as: class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { List<Data> data; … public void swap(ArrayList<Data> datas) { data.clear(); data.addAll(datas); notifyDataSetChanged(); } } Also there is a difference between list.clear(); list.add(data); and list = newList; The first is reusing … Read more

Android: how to refresh ListView contents?

To those still having problems, I solved it this way: List<Item> newItems = databaseHandler.getItems(); ListArrayAdapter.clear(); ListArrayAdapter.addAll(newItems); ListArrayAdapter.notifyDataSetChanged(); databaseHandler.close(); I first cleared the data from the adapter, then added the new collection of items, and only then set notifyDataSetChanged(); This was not clear for me at first, so I wanted to point this out. Take note … Read more

Android – Implementing search filter to a RecyclerView

in your adapter add new function for update the list public void updateList(List<DataHolder> list){ displayedList = list; notifyDataSetChanged(); } add textWatcher for search lets say you are using Edittext as search field searchField.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public … Read more

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

There are several ways to achieve this. The first option is easier, but bit more inefficient. Override getItemPosition in your PagerAdapter like this: public int getItemPosition(Object object) { return POSITION_NONE; } This way, when you call notifyDataSetChanged(), the view pager will remove all views and reload them all. As so the reload effect is obtained. … Read more

android – listview get item view by position

Use this : public View getViewByPosition(int pos, ListView listView) { final int firstListItemPosition = listView.getFirstVisiblePosition(); final int lastListItemPosition = firstListItemPosition + listView.getChildCount() – 1; if (pos < firstListItemPosition || pos > lastListItemPosition ) { return listView.getAdapter().getView(pos, null, listView); } else { final int childIndex = pos – firstListItemPosition; return listView.getChildAt(childIndex); } }

How to customize listview using baseadapter

main.xml: <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:paddingBottom=”@dimen/activity_vertical_margin” android:paddingLeft=”@dimen/activity_horizontal_margin” android:paddingRight=”@dimen/activity_horizontal_margin” android:paddingTop=”@dimen/activity_vertical_margin” tools:context=”.MainActivity” > <ListView android:id=”@+id/list” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_alignParentLeft=”true” android:layout_alignParentTop=”true” > </ListView> </RelativeLayout> custom.xml: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical” > <LinearLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” > <LinearLayout android:layout_width=”255dp” android:layout_height=”wrap_content” android:orientation=”vertical” > <LinearLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android:orientation=”vertical” > <TextView android:id=”@+id/title” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Video1″ android:textAppearance=”?android:attr/textAppearanceLarge” android:textColor=”#339966″ android:textStyle=”bold” /> </LinearLayout> … Read more

Custom Adapter getView() method is not called

The only reasons getView is not called are: getCount returns 0. you forget to call setAdapter on the ListView. If the ListView‘s visibility (or its container’s visibility) is GONE. Thanks to @TaynãBonaldo for the valuable input. ListView is not attached to any viewport layout. That is, mListView = new ListView(…) is used without myLayout.addView(mListView). In … Read more