public void user_chat(DataSnapshot dataSnapshot) {
Iterator i = dataSnapshot.getChildren().iterator();
items = new ArrayList<Chat_room>();
RecyclerView recyclerView=(RecyclerView)findViewById(R.id.activity_recycler);
LinearLayoutManager layoutManager=new LinearLayoutManager(RandomChatActivityTwo.this);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(new AdapterActivity(RandomChatActivityTwo.this,items,R.layout.activity_random_two));
while (i.hasNext()) {
chat_msg = String.valueOf(((DataSnapshot) i.next()).getValue());
chat_user_name = String.valueOf(((DataSnapshot) i.next()).getValue());
items.add(new Chat_room(chat_user_name, chat_msg));
adt.notifyDataSetChanged(); <- 작동을 안하는 듯 합니다;
}
-----------------------------------------------------------------
public class AdapterActivity extends RecyclerView.Adapter<AdapterActivity.ViewHolder> {
Context context;
List<Chat_room> items;
int item_layout;
public AdapterActivity(Context context, List<Chat_room> items, int item_layout) {
this.context=context;
this.items=items;
this.item_layout=item_layout;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_items,null);
return new ViewHolder(v);
}
//@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
final Chat_room item=items.get(position);
holder.name.setText(item.getName()+":"+item.getMsg()+"\n");
}
@Override
public int getItemCount() {
return this.items.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView name;
TextView msg;
public ViewHolder(View itemView) {
super(itemView);
name=(TextView)itemView.findViewById(R.id.chat_name);
msg=(TextView)itemView.findViewById(R.id.chat_message);
}
}
}
지금 상태는 데이터가 새로 입력되면 전에 있던 채팅창에 있는 텍스트를 덮어버립니다, 새로운 텍스트로 바뀌어버립니다. 저는 채팅창처럼 아래로 쭉 내려오게 하고 싶은데, 어떻게 하면 좋을까요?