简体   繁体   中英

Android ListView header (not section header)

i am relatively new to android development but i already have some experience in iOS and some years with Java so i learn really fast. However, i am not very familiar with all the different components in Android so maybe you can give me a hint how to accomplish what i try to do. But first, please take a look at my mockup:

在此处输入图片说明

I'm trying to reproduce the layout from my mockup. Most of it is no big deal for me but do you see the "Kontakte" and "Adressen" labels with the thin line below them? I want to use ListViews to display my contacts (Kontakte) and locations (Adressen) because each business partner (Geschäftspartner) can have 0..n of them. In my mockup programm (Pencil), the lables with the lines are called "List Header" but i am not able to find something similar in Android. I believe i could use the section headers of the ListView since i will only have one section if i use one ListView for contacts and one for locations but the sections headers look different. Can you help me?

If you want to use one ListView for contacts and one for locations you can opt for accomplishing your task in the xml that defines the layout using two TextView with the attribute style="?android:attr/listSeparatorTextViewStyle" , eg:

<TextView 
        android:id="@+id/textview_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?android:attr/listSeparatorTextViewStyle"
        android:text="Kontakte"/>

Thanks for the hint but i decided to go with another way. I now use a ListView for the whole activity. Then i create a custom adapter which i populate with my model classes. In the adapter itself, i chose between different view types based on the models i get. So the header area is one model, each of the contacts is a model and each location is a model. I also use plain strings for the section headers (Kontakte and Adressen). With one view for each type of model i can now easily create the layout i want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM