Liste Görünümü çağırırken ClassCastException.() addHeaderView?
Bir liste görünümü yukarıda yer istiyorum bu oldukça karmaşık bir düzeni var (RelativeLayouts, TextViews ve İmageViews içeren). Bu görünüm liste görünümü ile kaydırma.
Düzeni ekleyerek bu kodu kullanarak: liste görünümü için bir başlık olarak çalıştım
View v = inflater.inflate(R.layout.list_view, container, false);
View header = inflater.inflate(R.layout.header_layout, container, false);
// populate views in the header
mList = (ListView)v.findViewById(R.id.list);
mList.addHeaderView(header);
mAdapter = new ReviewsAdapter(getActivity());
mList.setAdapter(mAdapter); <-- error occurs here
ReviewsAdapter
yazdım BaseAdapter
uzanan özel bir adaptör.
Kod yürütme üzerine, bu hata alıyorum:
11-25 17:19:14.802: E/AndroidRuntime(1215): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
11-25 17:19:14.802: E/AndroidRuntime(1215): at android.widget.ListView.clearRecycledState(ListView.java:513)
11-25 17:19:14.802: E/AndroidRuntime(1215): at android.widget.ListView.resetList(ListView.java:499)
11-25 17:19:14.802: E/AndroidRuntime(1215): at android.widget.ListView.setAdapter(ListView.java:442)
11-25 17:19:14.802: E/AndroidRuntime(1215): at com.coppi.storefront.product.ProductReviewsFragment.onCreateView(ProductReviewsFragment.java:104)
I mList.addHeaderView(header)
satırı dışında açıklama hatası alıyorum. Ayrıca herhangi bir sorun ile liste görünümü olmayan başlık düzeni görüntüleyebilirsiniz.
Bu başlık düzenini içeriği ile ilgili bir şey var sanıyorum ama neden olacağına tam olarak emin değilim.
Burada başlık xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@ id/header_section"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_sides"
android:background="@color/pdp_availability_section_background" >
<TextView
android:id="@ id/header_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_sides"
android:paddingBottom="@dimen/margin_sides"
android:text="@string/ratings_reviews"
android:textColor="#000"
android:textSize="18dp" />
</RelativeLayout>
<RelativeLayout
android:id="@ id/body_section"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/header_section" >
<TextView
android:id="@ id/product_title"
style="@style/ProductTitleFont"
android:layout_marginBottom="@dimen/product_title_bottom_margin"
android:layout_marginLeft="@dimen/margin_sides"
android:layout_marginRight="@dimen/margin_sides" />
<RelativeLayout
android:id="@ id/attributes_section"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/product_title"
android:layout_centerHorizontal="true"
android:layout_margin="@dimen/margin_sides" >
<LinearLayout
android:id="@ id/overall_section"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom" >
<TextView
android:id="@ id/overall_label"
style="@style/ProductTitleFont"
android:layout_width="wrap_content"
android:text="@string/overall_rating" />
<ImageView
android:id="@ id/overall_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="@drawable/icon_rating_empty" />
<ImageView
android:id="@ id/overall_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_rating_empty" />
<ImageView
android:id="@ id/overall_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_rating_empty" />
<ImageView
android:id="@ id/overall_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_rating_empty" />
<ImageView
android:id="@ id/overall_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_rating_empty" />
<TextView
android:id="@ id/overall_score"
style="@style/ProductTitleFont"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp"
android:text="4.6" />
</LinearLayout>
<Button
android:id="@ id/rate_review_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/overall_section"
android:layout_marginBottom="@dimen/margin_sides"
android:layout_marginTop="@dimen/margin_sides"
android:text="@string/rate_review_button_text" />
</RelativeLayout>
<View
android:id="@ id/attributes_divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@id/attributes_section"
android:layout_marginBottom="@dimen/margin_sides"
android:layout_marginTop="@dimen/margin_sides"
android:background="@color/pdp_section_divider" />
<TextView
android:id="@ id/review_count"
style="@style/ProductTitleFont"
android:layout_width="wrap_content"
android:layout_below="@id/attributes_divider"
android:layout_marginLeft="@dimen/margin_sides"
android:text="0 " />
<TextView
style="@style/ProductTitleFont"
android:layout_width="wrap_content"
android:layout_alignBaseline="@id/review_count"
android:layout_marginRight="@dimen/margin_sides"
android:layout_toRightOf="@id/review_count"
android:text="@string/customer_reviews" />
<View
android:id="@ id/review_count_divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@id/review_count"
android:layout_marginBottom="@dimen/margin_sides"
android:layout_marginTop="@dimen/margin_sides"
android:background="@color/pdp_section_divider" />
</RelativeLayout>
</RelativeLayout>
Güncelleme:Başlık azaltmaya çalıştım .sadece tek bir TextView için dosya xml ve sorun devam ediyor. Sorun xml bir şey tarafından neden olmak olduğuna inanmıyorum.
CEVAP
FrameLayout
AbsListView
FrameLayout.LayoutParams
AbsListView.LayoutParams
çocuklarını düzeni parametreler dönüştürmek. Bu oyuncu seçimi başarısız.
View header = View.inflate(this, R.layout.header_layout, null);
bunu düzeltmek gerekir.
Edit: Açıklamalarda belirtildiği gibi, şişirmek call of ViewGroup Parametre değiştirme de iş yapar:
header = inflater.inflate(R.layout.header_layout, null, false);
Liste görünümü addHeaderView pozisyon ...
Nasıl kapalı (dairesel) bir liste Görü...
Neden Liste Görünümü öğeleri içerikler...
Android Liste Görünümü Renk Seçici...
- Liste Görünümü tıklatın Android nası...