Unknown.geeko Unknown.geeko - 1 year ago 106
Android Question

Android pass value from activity to adapter

I want to pass variable from activity to adapter.

My adapter looks like this

public SampleAdapter(Activity context, ArrayList<SampleBeans> data){
this.context = context;
this.data = data;

My Activity looks like this

newadapter = new SampleAdapter(this);

Gives me error SampleAdapter cannot be applied to the activity.

Answer Source

Simply add the values to the constructor.

public SimpleAdapter(Activity context, ArrayList<SimpleBeans> data, String mystring, int myInt){
  //use datas here

And use it like

myAdapter = new SimpleAdapter(this, data, myString, myInt);

Obiouvsly you can set all the datas you want, mine were some examples.

In your case you simply need to add the arrayList to the constructor.

myAdapter = new SimpleAdapter(this, myArrayList);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download