0

私は考えていた。ボタンを押して 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)

どんな助けでも大歓迎です!ありがとう!

4

1 に答える 1

0

inflate(int, activity, boolean)それは、メソッドのようなものがないからです。それはあるはずですinflate(int resId, Viewgroup parentContainer, boolean attachToParent)

于 2014-08-26T00:20:21.803 に答える