Here's my problem:
I have an AlbumActivity that lists all the albums name using RecyclerView.
When one item is clicked it will go to ImagesActivity where all of the images inside the Album will be listed. I also used RecyclerView. ImagesActivity has a toolbar menu that can add multiple images in case the user wants to add another images to the album. When the menu is clicked another activity will be opened to add images path to the database.
My problem is that when I go back to the ImagesActivity the images do not appear. The images will only appear when I only go again to AlbumActivity to view again the album's images. How can I notify the change quickly in the ImagesActivity.
Here's my Adapter:
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {
static List<GettersSetters> dbList;
static Context context;
ImageAdapter(Context context, List<GettersSetters> dbList) {
this.dbList = new ArrayList<GettersSetters>();
this.context = context;
this.dbList = dbList;
}
#Override
public ImageAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
R.layout.item_image, null);
ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return viewHolder;
}
#Override
public void onBindViewHolder(ImageAdapter.ViewHolder holder, int position) {
File imageFile = new File(dbList.get(position).getPath());
if(imageFile.exists()){
Bitmap img = decodeBitmapWithSize(dbList.get(position).getPath(),300,150, true);
holder.imageGallery.setImageBitmap(img);
}else{
holder.imageGallery.setImageResource(R.drawable.not_found);
}
}
#Override
public int getItemCount() {
return dbList.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public ImageView imageGallery;
public ViewHolder(View itemLayoutView) {
super(itemLayoutView);
imageGallery = (ImageView) itemLayoutView.findViewById(R.id.img_row);
itemLayoutView.setOnClickListener(this);
itemLayoutView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
Toast.makeText(context,"Delete Image",Toast.LENGTH_LONG).show();
return true;
}
});
}
#Override
public void onClick(View v) {
}
}
You will need to refresh the dbList after add images path to the database.
When you go back to the Images Activity, you get new dbList from database in onActivityResult. And you can refresh the dbList as follows:
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {
...
public void updateList(List<GettersSetters> dbList) {
this.dbList.clear();
this.dbList.addAll(dbList);
notifyDataSetChanged();
}
}
The most common way of doing it is to instantiate your List and Adapter in your activity, and call notifyDataSetChanged on your adapter whenever you change the data in the list.
For example, in your Activity class...
List<GetterSetter> list;
ImageAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
list = new ArrayList();
adapter = new ImageAdapter(this, list);
// you will also need to attach your adapter to your recyclerview.
// when you are ready to modify/add/delete items from the list, just do it and call notifyDataSetChanged
list.add(new GetterSetter());
adapter.notifyDataSetChanged(); // This will update your recyclerview to show one item, instead of an empty list
}
In short, you obviously pass your Adapter a List. Any time you change any data in the list, make sure to call notifyDataSetChanged() on the adapter object.
when coming back to Images Activity in onResume method call like this
public void onResume{
youradapter.refreshrecyclerview(); // implement this method in adpater or simply call here
adpater.notifiDataSetChanged();
}
In adpater implement this method,
public void refreshrecyclerview(){
notifiDataSetChanged();
}
once you add the images, are you calling notifydatasetchanged() ? https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html#notifyDataSetChanged()
this needs to be called in your ImagesActivity after you add your images to the dbList.
Please read the documentation in the above link to understand notifydatasetchanged()
This method basically informs the Adapter that the data in the dbList is updated and hence it has to refresh the UI.
Related
I have a fragment Users which has 3 other fragments in it (tabs). For one tab ( called Friends2Fragment ) I made a recycler View and made an adapter for it. In each item of RecyclerView I have a button "Add friend" and I want to call it from Friends2Fragment, not to call it from the adapter because I can't use Firestore Database properly.
RecyclerViewInterface:
public interface RecyclerViewInterface {
void onItemClick(int position, String button_pressed);
}
Friends2Fragment.java :
public void onStart(){
super.onStart();
recyclerView = (RecyclerView) v.findViewById(R.id.recycler);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
friendslist = new ArrayList<>();
myAdapter = new MyAdapter(friendslist,v.getContext());
recyclerView.setAdapter(myAdapter);
------ Firestore operations ------
}
#Override
public void onItemClick(int position, String button_pressed) {
switch ( button_pressed ){
case "ADD_FRIEND":
Log.d(TAG, "item clicked: " + friendslist.get(position).username);
}
}
MyAdapter.java :
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.myViewHolder> {
Context context;
public ArrayList<User> userArrayList;
public MyAdapter(ArrayList<User> userArrayList, Context context) {
this.userArrayList = userArrayList;
this.context = context;
}
public Context getContext() {
return context;
}
public ArrayList<User> getUserArrayList() {
return userArrayList;
}
#NonNull
#Override
public MyAdapter.myViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
MyAdapter.myViewHolder myViewHolder = new MyAdapter.myViewHolder(v);
myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((Friends2Fragment)context).onItemClick(myViewHolder.getAdapterPosition(),"ADD_FRIEND");
}
});
return myViewHolder;
}
#Override
public void onBindViewHolder(#NonNull MyAdapter.myViewHolder holder, int position) {
User user = userArrayList.get(position);
holder.usernamerecycle.setText(user.username);
}
#Override
public int getItemCount() {
return userArrayList.size();
}
public void filterList(List<User> filteredList){
userArrayList = (ArrayList<User>) filteredList;
notifyDataSetChanged();
}
public class myViewHolder extends RecyclerView.ViewHolder{
TextView usernamerecycle;
Button addbutton;
View rootview;
public myViewHolder(#NonNull View itemView) {
super(itemView);
rootview = itemView;
usernamerecycle = itemView.findViewById(R.id.usernamerecycler);
addbutton = itemView.findViewById(R.id.addfriendbutton);
}
}
}
The problem is at this line : ((Friends2Fragment)context).onItemClick(myViewHolder.getAdapterPosition(),"ADD_FRIEND"); in onCreateViewHolder method in MyAdapter.
I have this error : Inconvertible types; cannot cast 'android.content.Context' to 'com.example.birthday.Fragments.Friends2Fragment'
Please help me ..
A Fragment isn't a Context (that's not one of its supertypes) so that cast is impossible, that's why you're getting the error.
I think you should organise it like this: your Adapter holds a bunch of User objects, right? It displays those, and you have a click listener on each ViewHolder that knows which index in the User list it's currently displaying, and it wants to inform some listener when it's clicked. That index is an internal detail really, it would make more sense to look up the actual User, and provide that to the listener.
The simplest way is to just provide your fragment as a listener. First store it in your adapter:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.myViewHolder> {
// store a reference to your fragment
private Friends2Fragment listener;
// add a function to provide that fragment
public void setListener(Friends2Fragment: listener) {
this.listener = listener
}
...
public MyAdapter.myViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
...
myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (listener != null) {
// look up the actual user
User user = userArrayList.get(myViewHolder.getAdapterPosition());
// call a function on your fragment
listener.onItemClick(user, "ADD_FRIEND");
}
}
});
}
Then add the callback function your adapter uses, and also set your fragment on the adapter as a listener:
// Friends2Fragment
// You should REALLY be doing this in onViewCreated or something, so this setup happens once.
// You're losing all your state by creating a new adapter whenever the user returns to the app
public void onStart(){
...
myAdapter = new MyAdapter(friendslist,v.getContext());
// set the fragment as the listener
myAdapter.setListener(this);
recyclerView.setAdapter(myAdapter);
}
// now add the function the adapter calls
private void onItemClick(User user, String someString) {
// handle the clicked user
}
A better way is to create an interface with all the events that need to be handled, and make your Fragment implement those. It breaks the hard association with the Fragment since you could pass any object that implements those functions, and it's also clearer because the interface kinda documents all the data the adapter produces, and that a listener needs to be able to handle. Something like this:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.myViewHolder> {
// the listener is now something that implements the Callbacks interface
private Callbacks listener;
...
// nesting it inside MyAdapter makes the path MyAdapter.Callbacks, which makes it clear
// exactly what it is and what it relates to, and kinda gives the Adapter "ownership"
interface Callbacks {
void addFriend(User user)
}
And then you just make the Fragment implement that interface
public class Friends2Fragment() extends Fragment implements MyAdapter.Callbacks {
...
// implement all the callbacks you need to handle
override public void addFriend(User user) {
// do the thing
}
// set it in the same way, since this Fragment implements MyAdapter.Callbacks
myAdapter.setListener(this);
Which is a bit neater and cleaner, I think - but slightly more work. Also if you notice, I renamed the callback function from the generic handleItemClick to the more specific addFriend - so instead of having to pass a String saying what kind of click it is, you just have a function for each event you want to handle, and you can name them appropriately
I am new to android development and encountered an issue while development. First of all look at the design which I want to make.
https://imgur.com/wja71Fl
In the image, the size list is fetched from the server and shown, but here what I want is that suppose another size 11 is given then it should automatically move to the next line. So what I know that recycler view can't be used here. Now how can I achieve this also another point is that how can I make that only one item is selected from the collection of the sizes and selecting another size should de-select the previously selected size. Please provide me some good way to achieve both the targets inefficient way.
To Achive this view . you can use recyclerview with GridLayoutManager . in gridview we have set number of item is one row . try this code to achive this view. in this code i have used a recycler view with a gridview . in this code i have implement only one item select check .
CODE
FirstActivity
public class FirstActivity extends AppCompatActivity{
RecyclerView recycler_view;
GridLayoutManager manager;
static int selectItem=-1;
CustomAdapter customAdapter;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
initView();
}
private void initView(){
ArrayList<String> list=new ArrayList<>();
list.add("8");
list.add("10");
list.add("11");
list.add("12");
list.add("14");
list.add("16");
list.add("18");
recycler_view=findViewById(R.id.recycler_view);
manager=new GridLayoutManager(this, 5);
recycler_view.setLayoutManager(manager);
customAdapter=new CustomAdapter(this, list);
recycler_view.setAdapter(customAdapter);
}
}
CustomAdapter
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.MyHolder>{
Context context;
ArrayList<String> dataList;
public CustomAdapter(Context context, ArrayList<String> dataList, ){
this.context=context;
this.dataList=dataList;
}
#NonNull
#Override
public MyHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i){
View view=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_custom,viewGroup,false);
MyHolder myHolder=new MyHolder(view);
return myHolder;
}
#Override
public void onBindViewHolder(#NonNull MyHolder myHolder, final int i){
//check select item position
if(selectItem==i){
myHolder.textView.setTextColor(Color.RED);
}else {
myHolder.textView.setTextColor(Color.BLACK);
}
myHolder.textView.setText(dataList.get(i));
myHolder.itemView.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
selectItem=i;
notifyDataSetChanged();
}
});
}
#Override
public int getItemCount(){
return dataList.size();
}
public class MyHolder extends RecyclerView.ViewHolder{
TextView textView;
public MyHolder(#NonNull View itemView){
super(itemView);
textView=itemView.findViewById(R.id.text_tv);
}
}
}
I Hope It work for you, if any query comment me
I am creating an AlertDialog custom class, called ActionDialog, which will contains a RecyclerView containing Buttons. I have a List of Button that I populate in the custom class ActionDialog (for now i just populate with useless Button just to try to use it, except one which I create in another class).
The problem is that when i create the AlertDialog, all buttons are showing empty, they are showed but with no text/no clicklistener (as you can see in the image below).
(I have added a custom ActionListener to a Button in another class and then give it as parameter in ActionDialog class. Will it lose the ActionListener?)
Here is the result.
I will leave here my ActionDialog class code, and the adapter class.
This is ActionDialog class:
public class ActionDialog extends AlertDialog{
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
private Button actionButtons;
private List<Button> buttons;
private Activity context;
public ActionDialog(#NonNull Activity context, Button actionButtons) {
super(context);
this.context = context;
this.actionButtons = actionButtons;
buttons = new ArrayList<>();
initButton();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
}
private void initButton(){
initZoneButton();
//TODO init all buttons
Button b1 = new Button(context);
b1.setText("ExampleButton1");
Button b2 = new Button(context);
b2.setText("ExampleButton2");
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String a;
}
});
buttons.add(b1);
buttons.add(b2);
}
private void initZoneButton(){
buttons.add(actionButtons); //this button is created in another class and give as parameter in this class
}
public void createDialog(){
Builder mBuilder = new Builder(context);
View view = context.getLayoutInflater().inflate(R.layout.dialog_actionbuttons_layout, null);
mRecyclerView = view.findViewById(R.id.dialog_actionbuttons_rv);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(context);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new ActionButtonsAdapter(buttons);
mRecyclerView.setAdapter(mAdapter);
mBuilder.setView(view);
mBuilder.create().show();
}
}
Here is the RecyclerView adapter class:
public class ActionButtonsAdapter extends RecyclerView.Adapter<ActionButtonsAdapter.ViewHolder>{
private List<Button> dataButtons;
static class ViewHolder extends RecyclerView.ViewHolder {
Button actionButton;
ViewHolder(View v) {
super(v);
actionButton = v.findViewById(R.id.action_button_rv);
}
}
public ActionButtonsAdapter(List<Button> dataButtons){
this.dataButtons = dataButtons;
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.actionButton = dataButtons.get(position);
//i think the problem is here, maybe
}
#Override
public ActionButtonsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_actionbutton_layout, parent, false);
return new ViewHolder(v);
}
#Override
public int getItemCount() {
return dataButtons.size();
}
}
I think in the onBindViewHolder method you should do what ever you want to do with your button.
Also there is no need for the list of buttons here. Make a list the data you need to be held in the Buttons RecyclerView.
I have a RecyclerView that will display Genres for restaurants lets say, So I will create a List of strings to hold these genres names (chickens, meats, etc,..)
Setting its text
holder.actionButton.setText(// Make use of position here);
Or Click Listeners.
Update
You can check google samples for recyclerview here
#Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
Log.d(TAG, "Element " + position + " set.");
// Get element from your dataset at this position and replace the contents of the view
// with that element
viewHolder.getTextView().setText(mDataSet[position]);
}
wheres mDataset is Array of Strings.
I was trying to create a recyclerView that shows a list of current statusbar notifications . I have created a custom adapter (NotiRecyclerAdapter) that takes a List of NotificationItemInformation
public class NotificationItemInformation
{
int iconId,noitId;
String packageName;
Drawable notiIcon;
}
I am using an SQLite DB to store all the notifications.
The NotificationListenerService writes and deletes from the DB whenever a notification is posted or removed.
I use a method called
public List<NotificationItemInformation> ReadNotilist (Context context);
( which is inside myDBHelper ) to read the contents of the DB to a List of NotificationItemInformation called data (which is global,public and static in my Main Activity ) .
then I use adapter (which is also global,public and static in my Main Activity ) to take the data and set it to the RecyclerView inside the onCreate method of my MainActivity.
So far everything is working well. and i can see the RecyclerView populated with the current StatusBar notification.
The problem is that the list does not update (if a new notification comes) till i restart the activity . I tried calling...
MainActivity.data.clear();
MainActivity.data = dbh.ReadNotilist(this); // dbh is DBhelper object
MainActivity.adapter.notifyDataSetChanged();
...inside onNotificationPosted (after the adding into DB) of my NotificationListenerService . But still the RecyclerView is not getting updated till I restart the activity.
Here is my MainActivity if you want to take a look.
public class MainActivity extends AppCompatActivity
{
SQLiteDatabase db;
DBHelper dbh;
RecyclerView notificationIconRecyclerView;
public static NotiRecyclerAdapter adapter;
public static List<NotificationItemInformation> data = Collections.EMPTY_LIST;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dbh = new DBHelper(this);
db = dbh.getDb();
notificationIconRecyclerView = (RecyclerView) findViewById(R.id.notificationIconRecyclerView);
data = dbh.ReadNotilist(this);
adapter = new NotiRecyclerAdapter(this,data);
notificationIconRecyclerView.setAdapter(adapter);
notificationIconRecyclerView.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,true));
}
}
Here is my custom Adapter for the RecyclerView
public class NotiRecyclerAdapter extends RecyclerView.Adapter<NotiRecyclerAdapter.MyViewHolder>
{
private LayoutInflater inflater;
List<NotificationItemInformation> data = Collections.emptyList();
NotiRecyclerAdapter(Context context, List<NotificationItemInformation> data)
{
inflater = LayoutInflater.from(context);
this.data = data;
}
#Override
public void registerAdapterDataObserver(RecyclerView.AdapterDataObserver observer)
{
super.registerAdapterDataObserver(observer);
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
View view = inflater.inflate(R.layout.custom_recyclerview_item,parent,false);
MyViewHolder holder = new MyViewHolder(view);
return holder;
}
#Override
public void onBindViewHolder(MyViewHolder holder, int position)
{
NotificationItemInformation current = data.get(position);
holder.recyclerItemIcon.setImageDrawable(current.notiIcon);
}
#Override
public int getItemCount()
{
return data.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder
{
ImageView recyclerItemIcon;
public MyViewHolder(View itemView)
{
super(itemView);
recyclerItemIcon = itemView.findViewById(R.id.notiRecyclerItemIcon);
}
}
}
Do not reset the reference to the data object. Instead try something like this:
MainActivity.data.clear();
MainActivity.data.addAll(dbh.ReadNotilist(this));
MainActivity.adapter.notifyDataSetChanged();
In your adapter's constructor, you write
this.data = data;
This assigns the List<NotificationItemInformation> passed to the constructor to your adapter's data field. Your adapter is constructed like this:
adapter = new NotiRecyclerAdapter(this,data);
This means that your MainActivity.data field and your adapter.data field are both referring to the same list.
Later you write:
MainActivity.data.clear();
MainActivity.data = dbh.ReadNotilist(this);
MainActivity.adapter.notifyDataSetChanged();
The first line clears MainActivity.data and adapter.data (remember, they're the same list due to the way the adapter was constructed). The second line assigns a new list to MainActivity.data, but does not affect adapter.data in any way. The third line notifies the adapter that the data set has changed (which it has; it has been cleared), but your adapter won't "see" the new info from dbh.ReadNotilist().
AChez9's answer works because using addAll() instead of assignment (=) means that MainActivity.data and adapter.data are still pointing to the same List, so the adapter will "see" the new info.
This is why it is often correct to create copies of lists when you accept them from an outside source. In other words, your adapter's constructor might want to do this:
this.data = new ArrayList<>(data);
This will mean that it is "safe" from changes to the list passed to it (in this case, MainActivity.data). But this means you also need to expose a way for your activity to update your adapter correctly. I'd recommend a method like this:
public void updateData(List< NotificationItemInformation> data) {
this.data = new ArrayList<>(data);
notifyDataSetChanged();
}
i am showing arraylist getting from server to recyclerview.now i added pagination, its working fine and showing new list in recyclerview replacing previous list. but i want pagination like new list will concatenate to the existing list and show merged list(like facebok if i scrolldown after showing certain items it added new items to the list, concatenate with last list and show all the items) in recyclerview.
adapter constructor :
public NewsFeedAdapter (ArrayList<NewsFeedClass> newsFeedClassArrayList, Context context ){
this.context=context;
this.newsFeedClassArrayList=newsFeedClassArrayList;
}
adapter code:
public class NewsFeedAdapter extends RecyclerView.Adapter<NewsFeedAdapter.MyViewHolder>{
Context context;
private static ArrayList<NewsFeedClass> newsFeedClassArrayList=new ArrayList<>();
private NewsFeedClass newsFeedClass;
private String videoId="zDlMVlUriLw";
private int totalLikeWow; // total like,dislike,wow,bleh count;
AsyncTaskClass asyncTaskClass;
private NameShowWho_SharedPostAdapter nameShowWhoSharedPostAdapter;
NameShowWho_SharedPost_class nameShowWhoSharedPost_class;
private int changeValue;//like ad/less on button click
private ViewPagerAdapter viewPagerAdapter;
int previousItemsSize;
public NewsFeedAdapter (ArrayList<NewsFeedClass> newsFeedClassArrayList, Context context ){
this.context=context;
// this.newsFeedClassArrayList=newsFeedClassArrayList;
addItems(newsFeedClassArrayList);
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public MyViewHolder(View itemView) {
super(itemView);
}
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.newsfeed_adapter,parent,false);
return new MyViewHolder(view);
}
#Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
}
#Override
public int getItemCount() {
return newsFeedClassArrayList.size();
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public int getItemViewType(int position) {
return position;
}
private void addItems(List<NewsFeedClass> newItems) {
previousItemsSize = newsFeedClassArrayList.size();
// Append the new items to the old items
newsFeedClassArrayList.addAll(newItems);
// Notify the adapter about the newly added items
notifyItemRangeInserted(previousItemsSize, newItems.size());
}
}
please i need help me on this issue. i have tried but did not find any.
Here's one way to achieve this:
Create a new empty List in your adapter class constructor.
Add a new public method to update the adapter data with new items.
For example:
private List<String> mItems; // Demo data source
// Adapter constructor creates an empty list
public MyAdapter() {
mItems = new ArrayList<>();
}
public void addItems(List<String> newItems) {
int previousItemsSize = mItems.size();
// Append the new items to the old items
mItems.addAll(newItems);
// Notify the adapter about the newly added items
notifyItemRangeInserted(previousItemsSize, newItems.size());
}
Now, When you need to add a new set of items - just call the AddItems() method.
You just add item in your adapter like this
public NewsFeedAdapter (ArrayList<NewsFeedClass> newsFeedClassArrayList, Context context ){
this.context=context;
this.newsFeedClassArrayList=newsFeedClassArrayList;
}
after when you get new record then simple to add as below. you need to do this things in you Activity/Fragment class where you can set your adapter in you recyclerview.
adapter.addItems(newsFeedClassArrayList);
You should use addAll() to add data to existing list after receiving data from server originalList.addAll(listFromServer);
and then notify your adapter.
Let me know if it helps.