-3

私は Android アプリケーションを作成していて、リストからフェッチされているコメントのリストを持っていますが、それを edittext に記述してボタンで送信することにより、動的に追加したいと考えています。新しい cardView を追加して、編集テキストに書き込んだデータを入力することはできますか? どんな助けでも感謝します。ありがとう。

それは私の活動コードです

<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>

私のデータを更新するために、私はそれを使用します:

void refresh(List<Comment> commentsList){
        mAdapter = new CommentsAdapter(commentsList);
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.notifyDataSetChanged();
}

しかし、それは自動ではありません。フェイスブックみたいなものが欲しいです。

ありがとう。

4

1 に答える 1