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
newsPlace.addView(new ListView(parser.next());but it scolds that itβs the next one - Max Fadeevadapter.notifyDataSetChanged();with the adapter, update the adapter -adapter.notifyDataSetChanged();, if suddenly there is no - do it through the array and adapter - Jarvis_JlvInfo = (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 adapterArrayAdapter<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