I´m writing an Android application and have a list of comments which is being fetched from a list, but i want to add it dynamically, by writing it in a edittext and sending it with a button. Is it possible to add a new cardView and enter data that i write in the edittext? Any help would be appriciated. Thanks.
That´s my activity code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/linearLayout">
<LinearLayout
android:id="@+id/top_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#ffffff"
android:orientation="horizontal"
android:gravity="center_horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="volver"
android:id="@+id/backBut"
android:backgroundTint="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="COMENTARIOS"
android:id="@+id/ventas"
android:gravity="center_vertical"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textStyle="bold|italic"
android:typeface="sans"
android:textColor="#000000" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/refreshbutton"
android:layout_marginRight="10dp"
android:background="@drawable/reload"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/reciclador"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/top_bar"
android:padding="3dp"
android:scrollbars="vertical"
android:layout_marginBottom="50dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/commentlayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffff"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<EditText
android:id="@+id/commenttext"
android:hint="Escribe tu comentario"
android:layout_weight="0.9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageButton
android:layout_weight="0.1"
android:id="@+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/commenttext"
android:background="@drawable/send" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
For refresh my data I use that:
void refresh(List<Comment> commentsList){
mAdapter = new CommentsAdapter(commentsList);
mRecyclerView.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
}
But it´s not automatic. I want something like facebook.
Thanks.