Different row layouts in ListView

Implement the getItemViewType() and getViewTypeCount() for your adapter: @Override public int getViewTypeCount() { return 2; //return 2, you have two types that the getView() method will return, normal(0) and for the last row(1) } and: @Override public int getItemViewType(int position) { return (position == this.getCount() – 1) ? 1 : 0; //if we are at … Read more

Android: Radio button in custom list view

Here are the key ideas when a RadioButton is checked we must call notifyDataSetChanged(), so that all views get updated. when a RadioButton is checked we must set a selectedPosition, to keep track of which RadioButton is selected Views are recycled inside ListViews. Therefore, their absolute position changes in the ListView. Therefore, inside ListAdapter#getView(), we … Read more

How to update/refresh specific item in RecyclerView

You can use the notifyItemChanged(int position) method from the RecyclerView.Adapter class. From the documentation: Notify any registered observers that the item at position has changed. Equivalent to calling notifyItemChanged(position, null);. This is an item change event, not a structural change event. It indicates that any reflection of the data at position is out of date … Read more

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