Note that there are some explanatory texts on larger screens.

plurals
  1. POJSOUP and ListView
    primarykey
    data
    text
    <p>I'm building a personal app that, using JSOUP, puts the text of certain links into a ListView. For each link there should be a corresponding entry in ListView with the text from that link. When I run the app it successfully parses all of these texts. However, it places all of the text clumped up together in a single ListView entry then does the exact same thing over for consecutive entry. Where am I going wrong? Relevant code below:</p> <pre><code>public class MainActivity extends Activity { public Elements beer; public ArrayList&lt;String&gt; beerList = new ArrayList&lt;String&gt;(); private ArrayAdapter&lt;String&gt; adapter; private ListView lv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv = (ListView) findViewById(R.id.listView1); new NewThread().execute(); adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.simple_list_item_1, R.id.beer_name, beerList); } public class NewThread extends AsyncTask&lt;String, Void, String&gt; { @Override protected String doInBackground(String... arg) { Document doc; try { doc = Jsoup.connect("URLURLURLURL").userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0").get(); beer = doc.select("a[href*=URL.com/URL/]"); beerList.clear(); for (Element beers : beer) { beerList.add(beer.text()); } } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String result) { lv.setAdapter(adapter); } } } </code></pre> <p>A visual representation of what I'm currently getting:</p> <ul> <li>Item1 Item2 Item3 Item4 Item5 </li> <li>Item1 Item2 Item3 Item4 Item5 </li> <li>Item1 Item2 Item3 Item4 Item5 </li> <li>Item1 Item2 Item3 Item4 Item5</li> <li>Item1 Item2 Item3 Item4 Item5</li> </ul> <p>vs. what I want to be getting:</p> <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4</li> <li>Item 5</li> </ul> <p>Many thanks!</p> <pre><code>activity_main.xml: &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" &gt; &lt;ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" &gt; &lt;/ListView&gt; &lt;/RelativeLayout&gt; </code></pre> <p>simple_list_item_1.xml:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/beer_name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dip" android:textSize="16dip" android:textStyle="bold"/&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload