0

ListView にヘッダーを追加しようとしていますが、残念ながら次のエラーが発生します。

10-28 01:35:29.394: E/AndroidRuntime(17389): FATAL EXCEPTION: main
10-28 01:35:29.394: E/AndroidRuntime(17389): java.lang.ClassCastException: android.widget.HeaderViewListAdapter cannot be cast to com.hb.views.PinnedSectionListView$PinnedSectionListAdapter
10-28 01:35:29.394: E/AndroidRuntime(17389):    at com.hb.views.PinnedSectionListView$2.onScroll(PinnedSectionListView.java:91)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1340)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.widget.ListView.layoutChildren(ListView.java:1762)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.widget.AbsListView.onLayout(AbsListView.java:2012)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.View.layout(View.java:14296)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.View.layout(View.java:14296)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.View.layout(View.java:14296)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.View.layout(View.java:14296)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:678)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.View.layout(View.java:14296)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.View.layout(View.java:14296)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.View.layout(View.java:14296)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.View.layout(View.java:14296)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.Choreographer.doFrame(Choreographer.java:532)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.os.Handler.handleCallback(Handler.java:730)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.os.Looper.loop(Looper.java:137)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at android.app.ActivityThread.main(ActivityThread.java:5289)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at java.lang.reflect.Method.invokeNative(Native Method)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at java.lang.reflect.Method.invoke(Method.java:525)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
10-28 01:35:29.394: E/AndroidRuntime(17389):    at dalvik.system.NativeStart.main(Native Method)

私のコード:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_cat, null);
    return view;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    TextView header = new TextView(getActivity());
    header.setText("Header");
    getListView().addHeaderView(header);

    // ... adding objects to the adapter ...

    ArticleAdapter adapter = new ArticleAdapter(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, objects);
    setListAdapter(adapter);
}

pinned-section-listview ライブラリを使用しています。

前もって感謝します!

4

1 に答える 1

1

ヘッダーを追加しようとしました getListView().addHeaderView(header);

これにより、listview はアダプタをもう 1 つのアダプタでラップしますがHeaderViewListAdapter、ライブラリは独自のアダプタであると想定します。

// get expected adapter or fail
PinnedSectionListAdapter adapter = (PinnedSectionListAdapter) view.getAdapter();

使用したライブラリを修正するか、作者にバグを投稿するか、使用しないようにします。addHeader

于 2013-10-28T00:38:18.433 に答える