Development issue/problem:

I used this code to display two lists, one above the other.

The problem is that each of the two views in the list takes up half the screen.
I add a title to both lists, something like this.

LevelAdapter = new LevelAdapter(getActivity(),
R.layout.list_item, weather_data) ;

Header view = inflater.inflate(R.layout.header2, null);
Header view2 = inflater.inflate(R.layout.header, null);
lv2.setAdapter(adapter) ;

I want the title of the second list to appear after the end of the first. How do you do that? How can I make the second list start at the end of the first?
Thank you.

How can I solve this problem?

Solution 1:

Use this:

Scrap the linear format. Use a relative layout and place two list displays as shown.


social class utility {

public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter ==zero) {
// Condition

int totalHeight = 0;
int desiredWidth = MeasureSpec.makeMeasuresSpec(listView.getWidth(), MeasureSpec.AT_MOST);
for (int i = 0; i

In your business:

lv2.setAdapter(adapter) ;

Utility.setListViewHeightBasedOnChildren(lv1) ;
Utility.setListViewHeightBasedOnChildren(lv2) ;

Solution 2:

Android how to display 2 listviews in one activity one after the other –

com.example.listviewin1xmldemo package ;

import android.os.bundle; import; import
android.view.view; import
android.view.MeasureSpec; import
android.view.ViewGroup; import
android.widget.ArrayAdapter; import
android.widget.ListAdapter; import
android.widget.ListView ;

The MainActivity public class extends the ActionBarActivity {.

private list mListView1, mListView2 ;

private string [] data1 = {Hiren, Pratik, Dhruv, Narendra, Piyush, Priyank} ;
private string [] data2 = {Kirit, Miral, Bhushan, Jiten, Ajay, Kamlesh} ;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState) ;
setContentView(R.layout.activity_main) ;

mListView1 = (ListView)findViewById(;
mListView2 = (ListView)findViewById( ;

mListView1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, data1));
mListView2.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, data2))


public static class ListUtils {
public static gap collectionDynamic height (ListView mListView) {
ListAdapter mListAdapter = mListView.getAdapter();
if (mListAdapter ==zero) {
// if adapter is null
int height = 0;
int desiredWidth = MeasureSpec.makeMeasureSpec(mListView.getWidth(), MeasureSpec.UNSPECIFIED);
for (int i = 0; i

Solution 3:

You must use ExpandableListView ( Instead of two list views, you have two sections, but they are aligned (including titles) as you described.

Solution 4:

Using multiple ListViews in the same container is not good practice. This leads to measurement and performance problems.
It is preferable to use a single list view with multiple view types. In your case, the view types can be: listview1_viewtype, listview2_viewtype, listview2_header_viewtype. Only the header can be used for the first header of ListView.

Solution no. 5:

When weights are specified, the height should be specified as 0dp or wrap_content. but you do not need to edit your xml file as shown below. I hope it works.

As you indicated in your comment, I am changing my position as requested.

1- : Create a list view with only 2 lines

1.1- : Add the list view as a child of the row in the first list view #1.

1.2- : Add another list view as child of the second line of the first list view #1.

I hope you can succeed this way.

Solution no. 6:

I’m also new to Android and I have something similar (not really, but kind of a workaround), but much easier by creating a layout file and putting the required number of views in it, and another XML format and wrapping the previously created layout in ScrollView.

Suppose you have a layout called two_listview_layout.xml which is defined as follows

RelativeLayout is optional here, but you can play around with your needs and layouts.

Now create another layout with this layout wrapped in ScrollView. Because ScrollView can only have one direct child, you as the child have this complete layout.

Name this layout (below) as final_layout.xml.

Now expand this final_layout.xml file into your snippet/activity and use the identifiers listed in the two_listview_layout.xml file to access one of the list views.

The output is something like this: (Sorry for the poor quality screenshot :p ) Trailers and reviews – both are lists of views here.

Android how to display 2 listviews in one activity one after the other –

Solution no. 7:

Try using ScrollView and LinearLayout:


private ListView list1, list2 ;
private String [] data1 ={H, P, D, N, P, P} ;
private String [] data2 ={K, M, B, K, A, K} ;
protected void onCreate(Bundle savedInstanceState) {
list1 = (ListView) findViewById(;
list2 = (ListView) findViewById( ;

list1.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,,data1));
list2.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,,data2))


Solution no. 8:

Adding layout_weight worked for me.

Solution no. 9:

Try a relative layout:

Good luck!

how to combine two listview in androidmultiple listview in scrollview androidtwo listview inside scrollview flutterlistview set multiple adapterslistview androidcustom listview in android examplelistview vs recyclerviewlist to detail android studiosimple_list_item_1android multi column listview arrayadapterhorizontal listview androidlistview not showing android studiogrid view in androidandroid multiple views in one activity exampleandroid multiple activities in one screenxamarin forms how to display 2 listviews in one pagemultiple xml in one activity in androidandroid listadapter exampletwo list view side by side androidandroid listview with different layouts for each row

You May Also Like

How to Download and Install Facebook Messenger on Windows 10 PC

Until recently, Facebook Messenger on Facebook could only be used with a…

Steps To Start And Join Live Voice Chat On Telegram

To attract more users to its cloud-based instant messaging solution, Telegram announced…

Something went wrong while downloading your template [Fix]

How to correct an error when loading a model? 1. Retrieve a…

Why Choosing an ITAD Company is Important to your Business

The destruction of hard drives as a means of data protection is…