Note that there are some explanatory texts on larger screens.

plurals
  1. POExtracting strings from ListView Items, adding chars?
    text
    copied!<p>I have a listView that displays the records from a database, and a setOnClickListener() for the items that pulls the text from the list and adds the String as an extra for an Intent.</p> <p>This all works fine, my list displays records with Text such as, City, Town, Village, and when i add new items this also works fine. My issue lies with when i use a toast to display the string passed to the intent, some extra Chars are added </p> <p>e.g. I click on the List item "town" and the toast displays "{pg=town}" how to i stop this from happening/ why is it happening?</p> <p>The code for the Adapter and onClick is as Follows. </p> <p>Thanks in advance.</p> <pre><code>public void listChange() { Cursor c = database.rawQuery("select * from Towns", null); c.moveToFirst(); primeTownlist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); while (!c.isAfterLast()) { primeTownMap = new HashMap&lt;String, String&gt;(); primeTownMap.put("pg", c.getString(1)); primeTownlist.add(primeTownMap); c.moveToNext(); } c.close(); primeGoalAdapter = new SimpleAdapter(this, primeTownlist, R.layout.primeTowns, new String[] { "pg" }, new int[] {R.id.bt_primeTown}); primeTowns.setAdapter(primeTownAdapter); } primeTowns.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; list, View view, int position, long id) { String title = list.getItemAtPosition(position).toString(); Intent i = new Intent("com.example.towns.town"); i.putExtra("town", title); startActivity(i); Toast.makeText(getApplicationContext(), (title), Toast.LENGTH_SHORT).show(); } }); </code></pre>
 

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