我想知道。有没有办法通过按下按钮将 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)
任何帮助是极大的赞赏!谢谢!