Android标题视图分别滚动到列表视图

时间:2012-05-11 12:55:21

标签: android commonsware-cwac

嗨我正在使用合并适配器创建列表视图。但我在标题方面遇到了一些问题。它们似乎独立于列表滚动,通常只是捕捉到页面顶部。我如何得到它以使标题保持原位?或者是否有人不会导致这种情况?

继承我的代码

arrayAdapter = new ArrayAdapter<String>(this, R.layout.single_item, newsList);
arrayAdapter2 = new ArrayAdapter<String>(this, R.layout.single_item, newsList2);
arrayAdapter3 = new ArrayAdapter<String>(this, R.layout.single_item, newsList3);


 RelativeLayout layout = new RelativeLayout(this);
 RelativeLayout.LayoutParams labelLayoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
    layout.setLayoutParams(labelLayoutParams);

    ImageView mImage = new ImageView(this);
    mImage.setBackgroundResource(R.drawable.titlerect);        
    layout.addView(mImage,labelLayoutParams);

    TextView latestFixtures;         
       latestFixtures = new TextView(this);
       latestFixtures.setText("Latest League Fixture");
       layout.addView(mImage,labelLayoutParams);


    ListView list = getListView();
       list.setTextFilterEnabled(true);




setListAdapter (arrayAdapter);




    adapter = new MergeAdapter();
    adapter.addView(layout);
    adapter.addAdapter(arrayAdapter);
    adapter.addView(layout);
    adapter.addAdapter(arrayAdapter2);
    adapter.addView(layout);
    adapter.addAdapter(arrayAdapter3);
    setListAdapter(adapter);

}   

05-15 13:35:14.489: E/ListView(1045): java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams
05-15 13:35:14.489: E/ListView(1045):   at android.widget.ListView.setupChild(ListView.java:1834)
05-15 13:35:14.489: E/ListView(1045):   at android.widget.ListView.makeAndAddView(ListView.java:1803)
05-15 13:35:14.489: E/ListView(1045):   at android.widget.ListView.fillDown(ListView.java:670)
05-15 13:35:14.489: E/ListView(1045):   at android.widget.ListView.fillFromTop(ListView.java:727)
05-15 13:35:14.489: E/ListView(1045):   at android.widget.ListView.layoutChildren(ListView.java:1646)
05-15 13:35:14.489: E/ListView(1045):   at android.widget.AbsListView.onLayout(AbsListView.java:1260)
05-15 13:35:14.489: E/ListView(1045):   at android.view.View.layout(View.java:7277)
05-15 13:35:14.489: E/ListView(1045):   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
05-15 13:35:14.489: E/ListView(1045):   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
05-15 13:35:14.489: E/ListView(1045):   at android.widget.TableLayout.onLayout(TableLayout.java:440)
05-15 13:35:14.489: E/ListView(1045):   at android.view.View.layout(View.java:7277)
05-15 13:35:14.489: E/ListView(1045):   at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-15 13:35:14.489: E/ListView(1045):   at android.view.View.layout(View.java:7277)
05-15 13:35:14.489: E/ListView(1045):   at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-15 13:35:14.489: E/ListView(1045):   at android.view.View.layout(View.java:7277)
05-15 13:35:14.489: E/ListView(1045):   at android.view.ViewRoot.performTraversals(ViewRoot.java:1203)
05-15 13:35:14.489: E/ListView(1045):   at android.view.ViewRoot.handleMessage(ViewRoot.java:1957)
05-15 13:35:14.489: E/ListView(1045):   at android.os.Handler.dispatchMessage(Handler.java:99)
05-15 13:35:14.489: E/ListView(1045):   at android.os.Looper.loop(Looper.java:143)
05-15 13:35:14.489: E/ListView(1045):   at android.app.ActivityThread.main(ActivityThread.java:4263)
05-15 13:35:14.489: E/ListView(1045):   at java.lang.reflect.Method.invokeNative(Native Method)
05-15 13:35:14.489: E/ListView(1045):   at java.lang.reflect.Method.invoke(Method.java:507)
05-15 13:35:14.489: E/ListView(1045):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-15 13:35:14.489: E/ListView(1045):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-15 13:35:14.489: E/ListView(1045):   at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

使用MergeAdapter 使用addHeaderView(),而不是两者都使用。