I use xml parser to display information in ListView, xml code

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingTop="24dp"> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dp"> <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent"/> </android.support.v7.widget.CardView> </LinearLayout> 

With this code I add parser objects to the sheet.

 XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser parser = factory.newPullParser(); URL input = new URL("news.xml"); parser.setInput(input.openStream(), null); while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equals("contact")) { list.add(parser.getAttributeValue(0) + "\n" + "\n" + parser.getAttributeValue(1) + "\n"); } parser.next(); } 

In the simplest test, all objects are in place, but in this case only one is shown. As far as I understand, every time you add an object, you need to create a new LinearLayout along with a widget and a list? can't figure out how to do it

  • I tried to do so in newsPlace.addView(new ListView(parser.next()); but it scolds that it’s the next one - Max Fadeev
  • list is what you have? if the array of data adapter.notifyDataSetChanged(); with the adapter, update the adapter - adapter.notifyDataSetChanged(); , if suddenly there is no - do it through the array and adapter - Jarvis_J
  • I am sorry, I forgot to specify. yes, it is an array and adapter lvInfo = (ListView) findViewById(R.id.listView); final ArrayList<String> list = new ArrayList<String>(); lvInfo = (ListView) findViewById(R.id.listView); final ArrayList<String> list = new ArrayList<String>(); and adapter ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, list); lvInfo.setAdapter(adapter); ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, list); lvInfo.setAdapter(adapter); - Max Fadeev
  • People, I beg you to help - Max Fadeev
  • adapter update? I do not see it in the code - Jarvis_J

2 answers 2

Problem solved. added the fillViewport="true" attribute to this NestedScrollView element, now everything is displayed correctly and all news is working

  • one
    If you have solved the problem, describe the solution in detail. - YurySPb ♦

You have CardView height height content. And it is equal to the height of one element of the list. So replace

 android:layout_height="wrap_content" 

on

 android:layout_height="match_parent" 
  • unfortunately did not help (still displays 1 news item - Max Fadeev
  • I dug on the Internet that it is impossible to put the leaves in NestedScrollView .... it helped, deleted the element, but now the markup does not work correctly ( - Max Fadeev
  • 3
    @MaxFadeev, well, we would have told you this immediately, if you had mentioned it) - YuriySPb ♦