Search code examples
androidlistviewsimpleadapter

Listview to SimpleAdapter not working


I have code in one Activity as shown below and it works well.

HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID, catid);
map.put(TAG_NAME, catname);                 
oslist.add(map);
list=(ListView)findViewById(R.id.listView1);                                
ListAdapter adapter = new SimpleAdapter(MainActivity.this, oslist,
R.layout.category_list,
new String[] { TAG_ID,TAG_NAME}, new int[] {
R.id.catid,R.id.catname});

While similar code in another Activity is not working...

ListAdapter adapter = new SimpleAdapter(newsList.this, oslist,
R.layout.category_list,
new String[] { TAG_ID,TAG_NAME}, new int[] {
R.id.catid,R.id.catname});
list.setAdapter(adapter);

It gives error like :

The constructor SimpleAdapter(newsList, ArrayList<HashMap<String,String>>, int, String[], int[]) is undefined

Solution

  • Where you have newsList.this you should be passing a Context, probably the Activity2.this, assuming your second Activity is called Activity2.