Android Open Source - Stack-Chat Messages Recycler View Adapter






From Project

Back to project page Stack-Chat.

License

The source code is released under:

MIT License

If you think the Android project Stack-Chat listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.noahhuppert.stackchat;
//from   www  .  j a va 2s  .c o  m

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.noahhuppert.stackchat.models.Message;

import java.util.ArrayList;

/**
 * Created by Noah Huppert on 11/18/2014.
 */
public class MessagesRecyclerViewAdapter extends RecyclerView.Adapter<MessagesRecyclerViewAdapter.ViewHolder>{
    public ArrayList<Message> messages;

    public static class ViewHolder extends RecyclerView.ViewHolder{
        public TextView messageContent;
        public TextView messageAuthor;

        public ViewHolder(View itemView){
            super(itemView);
            messageContent = (TextView) itemView.findViewById(R.id.messageContent);
            messageAuthor = (TextView) itemView.findViewById(R.id.messageAuthor);
        }
    }

    public MessagesRecyclerViewAdapter(ArrayList<Message> messages){
        this.messages = messages;
    }

    @Override
    public MessagesRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_message_view, parent, false);

        ViewHolder viewholder = new ViewHolder(view);//(TextView) view.findViewById(R.id.messageContent));

        return viewholder;
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position){
        viewHolder.messageContent.setText(messages.get(position).getContent());
        viewHolder.messageAuthor.setText("User Id: " + messages.get(position).getUserId());
    }

    @Override
    public int getItemCount(){
        return messages.size();
    }
}




Java Source Code List

com.noahhuppert.stackchat.ApplicationTest.java
com.noahhuppert.stackchat.MainActivity.java
com.noahhuppert.stackchat.MessagesRecyclerViewAdapter.java
com.noahhuppert.stackchat.controllers.HeaderBuilder.java
com.noahhuppert.stackchat.controllers.JellyKitNotificationController.java
com.noahhuppert.stackchat.controllers.NotificationController.java
com.noahhuppert.stackchat.controllers.PopNotificationController.java
com.noahhuppert.stackchat.fragments.RoomFragment.java
com.noahhuppert.stackchat.models.KVPair.java
com.noahhuppert.stackchat.models.Message.java
com.noahhuppert.stackchat.models.Room.java
com.noahhuppert.stackchat.models.User.java
com.noahhuppert.stackchat.modules.BaseStackChatModule.java
com.noahhuppert.stackchat.modules.StackChatModule.java
com.noahhuppert.stackchat.modules.StackChatModule.java
com.noahhuppert.stackchat.tasks.GetMessagesTask.java
com.noahhuppert.stackchat.tasks.UpdateRoomMessagesTask.java