Possible Duplicate:
Android - Adding Subitem to a listview
I have 2 arrays - Namearray & companyarray. I want to display it in the listview. I have managed to display the names in the list by using the following code:
ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this,
android.R.layout.simple_list_item_1, Namearray);
setListAdapter(adapter);
But how do I add a Sub Item to the list as a Company Name.
After following Sai Geetha's blog - I came out with following - But the list is appearing empty - it shows 2 black lines with no text on them. My Activity background is blue and I have checked in custom_row_view that the textview textcolor is black. Have I missed anything?
if(cur!=null && cur.getCount()>0)
{
List<Map<String, String>> data = new ArrayList<Map<String, String>>();
Log.w("count=","ct="+cur.getCount() );
for (int i=1;i<=cur.getCount();i++) {
Map<String, String> datum = new HashMap<String, String>(2);
Log.w("name=",cur.getString(0) );
Log.w("compname=",cur.getString(1) );
datum.put("Name",cur.getString(0));
datum.put("Company", cur.getString(1));
data.add(datum);
cur.moveToNext();
}
SimpleAdapter adapter = new SimpleAdapter(this, data,
R.layout.custom_row_view,
new String[] {"Name", "Company"},
new int[] {android.R.id.text1,
android.R.id.text2});
setListAdapter(adapter);
cur.close();
}