0

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
Tash Pemhiwa
  • 7,590
  • 4
  • 45
  • 49
Jose
  • 51
  • 2
  • 6

2 Answers2

0

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

Tash Pemhiwa
  • 7,590
  • 4
  • 45
  • 49
0

you have to pass context in the constructor of your adapter like:

//Declare global

Contect _ctx = youractivityname.this

and then pass it to your adapter like:

ListAdapter adapter = new SimpleAdapter(_ctx, oslist,R.layout.category_list,new String[] {    TAG_ID,TAG_NAME}, new int[] {R.id.catid,R.id.catname});
Pankaj Arora
  • 10,224
  • 2
  • 37
  • 59