0

hi I'm creating a list view using a merge adapter. but i'm having some issues with the headers . they seem to scroll to independently of the list often just snapping to the top of the page. how do i get it so that the headers stay in place?or does anyone no what could cause this?

heres my code

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);

}   

code

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)
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Luke Batley
  • 2,384
  • 10
  • 44
  • 76

1 Answers1

0

Either use MergeAdapter or use addHeaderView(), not both.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • thank you. problem is when i use addView(headrview) when i scroll it crashes the app when the header view comes on screen – Luke Batley May 14 '12 at 07:03
  • @LukeBatley: Use `adb logcat`, DDMS, or the DDMS perspective in Eclipse to examine LogCat and look at the stack trace associated with your "crash". – CommonsWare May 14 '12 at 21:27
  • @LukeBatley: Please re-read my answer. Your code is using both `MergeAdapter` and `addHeaderView()`. I cannot help you until you fix your code, to use either one or the other. – CommonsWare May 15 '12 at 11:26
  • hi i have updated the question now. ps thanks for your help i cant tell you how long i've been trying to get this to work. – Luke Batley May 15 '12 at 13:40
  • @LukeBatley: Get rid of your call to `layout.setLayoutParams()` and try again. `setLayoutParams()` on a widget or container is for that widget or container's *parent's* use, and the parent of your `RelativeLayout` is not another `RelativeLayout`. – CommonsWare May 15 '12 at 13:44
  • hi have done that and recieved this error The specified child already has a parent. You must call removeView() on the child's parent first – Luke Batley May 15 '12 at 13:53
  • @LukeBatley: You are trying to add the same child (`layout`) multiple times, which is not supported. You need to make several identical layouts instead. – CommonsWare May 15 '12 at 15:57