Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Item Text not showing in listView
    primarykey
    data
    text
    <p>I've been trying for a long time, and I think I have the code in place, but something is wrong because the item is not being added to the listView. Follows my code:</p> <pre><code>public class EditDoctors extends Activity implements OnClickListener { SimpleAdapter adapter; List&lt;HashMap&lt;String, String&gt;&gt; painItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); ListView editDoc; int[] to; String[] from; EditText addDoc, docPos; String row1, row2; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.editdoc); addDoc = (EditText) findViewById(R.id.newDoc); docPos = (EditText)findViewById(R.id.docPos); editDoc = (ListView) findViewById(R.id.editDoc); TextView textview = new TextView(this); textview.setText("This is the Songs tab"); Button adddocs = (Button)findViewById(R.id.addbutton); adddocs.setOnClickListener(this); from = new String[] { "row_1", "row_2" }; to = new int[] { R.id.row1, R.id.row2 }; adapter = new Adapter(this, painItems, R.layout.mylistlayout,from, to); editDoc.setAdapter(adapter); } public class Adapter extends SimpleAdapter { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); View row; public Adapter(Context context, List&lt;? extends Map&lt;String, String&gt;&gt; data, int resource, String[] from, int[] to) { super(context, data, resource, from, to); } } private void addItem() { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); map.put("row_1", row1); map.put("row_2", row2); painItems.add(map); adapter.notifyDataSetChanged(); } @Override public void onClick(View arg0) { row1 = addDoc.getText().toString(); Toast.makeText(this, row1, Toast.LENGTH_SHORT).show(); row2 = docPos.getText().toString(); adapter.notifyDataSetChanged(); addItem(); } </code></pre> <p>}</p> <p>This should create a 2-lined listItem, but it doesn't, the lines are empty(no text). The Toast you see in the OnClickMethod returns the text just fine, but the item I add has nothing in it. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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