On one, the ListView is displayed correctly, but not on the other.

There is exactly more than one String element in the array.

// ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ массив с катСгориями: ArrayList<String> titleCategories = categories[0]; // Находим список, создаСм Π°Π΄Π°ΠΏΡ‚Π΅Ρ€ ΠΈ присваиваСм Π°Π΄Π°ΠΏΡ‚Π΅Ρ€ списку: ListView listCategories = (ListView) findViewById(R.id.listCategories); ArrayAdapter<String> mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, titleCategories); listCategories.setAdapter(mAdapter); 

as a result, on the screen only the first element of the array. What am I doing wrong? I'll give you all the code for my xml markup:

 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_download" android:id="@+id/button_download" android:onClick="onClickGetCategories"/> <ProgressBar style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="100px" android:id="@+id/progressBar" android:layout_gravity="center_horizontal"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="..." android:id="@+id/titleCategory" android:layout_weight="0.16" /> <ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/listCategories" style="@style/TestListView" android:listSelector="@color/background_question_field" /> </LinearLayout> </ScrollView> 
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦

2 answers 2

ListView not designed to work inside ScrollView . The reverse is also true.

You have two options:

  1. Long and hard to google, spend days trying to make different hacks work, support the code with crutches and reinvent the wheel. Put up and go to point two.
  2. Redo the markup so that the ListView not inside the ScrollView .

If you choose option 2, then the easiest way to achieve your goals will be to transfer everything above ListView to its Header by ListView.addHeader(View v) . In this case, the ScrollView will no longer be needed and it can be removed, getting rid of all the associated bugs.


PS If, however, you still want to be perverted, then you need to measure the exact height of the markup of all ListView elements and in the code set their sum as the height of the ListView . But I warned)

  • Yes, thank you, it is, it all worked! - eugeniuskh

It's not about ScrollView. In this line:

 // ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ массив с катСгориями: ArrayList<String> titleCategories = categories[0]; 

You yourself take only one element of the array, because categories [0] is its first element.

Output

Make it easier. Remove

 // ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ массив с катСгориями: ArrayList<String> titleCategories = categories[0]; 

and change

 ArrayAdapter<String> mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, categories[0]); 
  • The fact is that: categories [0] is ArrayList <String> titleCategories, and categories [1] is ArrayList <String> descriptionCategories. Those. one array with the names of the categories, the second with their descriptions. - eugeniuskh
  • @eugeniuskh, you designed it funny, it was impossible to understand from the condition of it, so I figured out a possible error. - Vitalii Obideiko
  • Yes, I agree, a little confused you. - eugeniuskh