是否可以在不使用动态适配器的情况下在Android中创建多个静态Cardview(直接在布局xml中定义)?
我有一个Weather JSON对象,我正在尝试使用改造来解析它,我想将数据提供给静态cardview,而不是为其构建适配器。
XML:
<LinearLayout
android:layout_below="@id/openweather"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_below="@id/openweather"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/headerSmall1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"/>
<TextView
android:id="@+id/contentLarge1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/headerSmall1"
android:text="Test"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cardView2"
android:layout_below="@id/openweather"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/headerSmall2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"/>
<TextView
android:id="@+id/contentLarge2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/headerSmall2"
android:text="Test"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cardView3"
android:layout_below="@id/openweather"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/headerSmall3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"/>
<TextView
android:id="@+id/contentLarge3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/headerSmall3"
android:text="Test"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cardView4"
android:layout_below="@id/openweather"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/headerSmall4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"/>
<TextView
android:id="@+id/contentLarge4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/headerSmall4"
android:text="Test"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cardView5"
android:layout_below="@id/openweather"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/headerSmall5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"/>
<TextView
android:id="@+id/contentLarge5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/headerSmall5"
android:text="Test"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/>
</RelativeLayout>
</android.support.v7.widget.CardView> </LinearLayout>