Reputation: 81
Is it possible to use a single xml file for the "whole layout" (activity)? Can you "embed" the row layout, that is in a separate file, to the listview in the main layout xml?
So it look something like this
<LinearLayout>
...
<ListView>
<LinearLayout>
<ImageView>
<TextView>
...
</LinearLayout>
</ListView>
</LinearLayout>
If it is possible, how is it done, how do you use "id", adapter etc then?
Because you could use
<listview>
...
</listview>
and not only
<listview .../>
...I thought it maybe could be possible to put the row layout directly there inside, but dont know how to do, to get it to work if it is possible. Is it?
Would like to have one single layout xml file, per activity, instead of many small parts. Would be easier to get the whole picture then I think and simplify stuff. Any other ways to do achieve this maybe?
Upvotes: 0
Views: 245
Reputation: 6518
Its definitely possible to use single xml for listview and its cell layout
It will go like this
You are creating two layouts in xml
<LinearLayout android:id="@+id/listview_layout"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ListView android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout android:id="@+id/cell_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
.............do your cell layout here
</LinearLayout>
Here use listview_layout for setting your ContentView
setContentView(listview_layout)
and use cell_layout in any adapter to set cell layout
you will find good tutorials for setting custom adapters for listview on StackOverFlow
Hope this will solve your problem
Upvotes: 1