CWAC合并适配器出现问题:https://github.com/commonsguy/cwac-merge
当我一个接一个地添加视图和适配器时,这种方法很好用,但是当我尝试一个接一个地添加两个标题时,它崩溃了.这是我的工作:
这是第一个标题的布局:
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="horizontal" androID:weightSum="7" androID:baselineAligned="false" > <linearLayout androID:ID="@+ID/unsynced_layoutt" androID:layout_wIDth="0dp" androID:layout_height="match_parent" androID:layout_weight="6" androID:orIEntation="vertical" > <VIEw androID:layout_wIDth="match_parent" androID:layout_height="3dp" androID:background="@color/greenish" /> <TextVIEw androID:ID="@+ID/unsynced_txt" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_marginBottom="10dp" androID:gravity="center" androID:text="@string/unsynced_txt" /> <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:gravity="center" androID:text="@string/lorem_ipsum" /> <VIEw androID:layout_wIDth="match_parent" androID:layout_height="3dp" androID:layout_gravity="bottom" androID:background="@color/greenish" /> </linearLayout> <linearLayout androID:orIEntation="vertical" androID:layout_weight="1" androID:ID="@+ID/sync_close_notification" androID:layout_wIDth="0dp" androID:layout_height="match_parent" androID:background="@color/grey_bcknd"> <Imagebutton androID:ID="@+ID/menu_btn" androID:layout_wIDth="wrap_content" androID:layout_height="fill_parent" androID:layout_gravity="center" androID:layout_marginleft="10dp" androID:layout_marginRight="15dp" androID:background="@null" androID:contentDescription="@string/something" androID:src="@drawable/notification_close_x_green" /> </linearLayout></linearLayout>
第二个标题的布局:
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:background="@color/grey_bcknd" androID:orIEntation="vertical" > <VIEw androID:ID="@+ID/top_line" androID:layout_wIDth="match_parent" androID:layout_height="1dp" androID:Alpha="0.25" androID:background="@color/grey_line" /> <TextVIEw androID:ID="@+ID/receipt_header_txt" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_below="@+ID/top_line" androID:layout_marginleft="10dp" androID:text="@string/active_folders" androID:textcolor="#B4AA9E" /> <VIEw androID:layout_wIDth="match_parent" androID:layout_height="1dp" androID:layout_alignParentBottom="true" androID:layout_below="@+ID/receipt_header_txt" androID:Alpha="0.25" androID:background="@color/grey_line" /></relativeLayout>
这是我尝试实际添加的地方:
all_adapter = new MergeAdapter(); final VIEw notification = inflater .inflate(R.layout.unsynced_layout, null); TextVIEw notification_txt = (TextVIEw) notification.findVIEwByID(R.ID.unsynced_txt); notification_txt.setText("You have "+unsynced_nr+" unsynced items"); all_adapter.addVIEw(notification_txt); for(int i=0;i<dates.size();i++){ System.out.println("HERE "+i); VIEw header1 = inflater .inflate(R.layout.receipt_List_header, null); TextVIEw date_header_txt = (TextVIEw) header1.findVIEwByID(R.ID.receipt_header_txt); date_header_txt.setText(dates.get(i)); all_adapter.addVIEw(header1); ReceiptDataSource recs1 = new ReceiptDataSource(globalVIEw.getContext()); recs1.open(); ArrayList<Receipt> currentReceipts = recs.findReceiptsByDate(dates.get(i), folder_ID); recs1.close(); //ReceiptAdapter folder_receipts = new ReceiptAdapter(getActivity(), R.layout.receipt_item, R.layout.receipt_incomplete_item, currentReceipts); ReceiptCustomAdapter folder_receipts = new ReceiptCustomAdapter(globalVIEw.getContext(), R.layout.receipt_pager, currentReceipts, getActivity().getSupportFragmentManager()); all_adapter.addAdapter(folder_receipts); }
和堆栈跟踪:
08-06 11:54:15.558: E/AndroIDRuntime(20408): FATAL EXCEPTION: main08-06 11:54:15.558: E/AndroIDRuntime(20408): java.lang.classCastException: androID.Widget.linearLayout$LayoutParams cannot be cast to androID.Widget.AbsListVIEw$LayoutParams08-06 11:54:15.558: E/AndroIDRuntime(20408): at androID.Widget.ListVIEw.measureScrapChild(ListVIEw.java:1170)08-06 11:54:15.558: E/AndroIDRuntime(20408): at androID.Widget.ListVIEw.measureHeightOfChildren(ListVIEw.java:1252)
如果我评论这一行:
all_adapter.addVIEw(notification_txt);
代码不再崩溃了.
任何建议高度赞赏,谢谢.
解决方法:
因为MergeAdapter需要AbsListVIEw.LayoutParams,所以您遇到了此问题.尝试这个:
final VIEw notification = inflater.inflate(R.layout.unsynced_layout, null);TextVIEw notification_txt = (TextVIEw) notification.findVIEwByID(R.ID.unsynced_txt);notification_txt.setText("You have "+unsynced_nr+" unsynced items");AbsListVIEw.LayoutParams layoutParams = new AbsListVIEw.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);notification_txt.setLayoutParams(layoutParams);all_adapter.addVIEw(notification_txt);
但是,如果您试图将整个视图简单地添加到您的mergeadapter中,则代替all_adapter.addVIEw(notification_txt);你可以说:all_adapter.addVIEw(notification);
总结以上是内存溢出为你收集整理的合并适配器标头崩溃全部内容,希望文章能够帮你解决合并适配器标头崩溃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)