私は考えていた。ボタンを押して CardViews を RecyclerView に追加する方法はありますか?
つまり、この XML で CardView を追加できるということです
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cardrl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity$MainFragment">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:foreground="?android:attr/selectableItemBackground"
android:id="@+id/CardView_1"
android:layout_width="match_parent"
android:layout_height="70dp"
android:elevation="2dp">
<TextView
android:layout_gravity="top|right"
android:text="@string/card_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.v7.widget.CardView>
そして、作成する前に TextView にデータを入力できるようにしますか?
多くの人が次のように言うことを知っています:
RelativeLayout rl = (RelativeLayout) findById(R.id.rl);
LayoutInflater layoutInflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rl.addView(1, layoutInflater.inflate(R.layout.content_layout, this, false) );
しかし、何らかの理由で機能しませんCannot resolve method Inflate(int, activity, boolean)
どんな助けでも大歓迎です!ありがとう!