Android pass value from activity to adapter

后端 未结 2 1737
广开言路
广开言路 2021-01-06 04:53

I want to pass variable from activity to adapter.

My adapter looks like this

  public SampleAdapter(Activity context, ArrayList da         


        
2条回答
  •  不要未来只要你来
    2021-01-06 05:20

    Simply add the values to the constructor.

    public SimpleAdapter(Activity context, ArrayList 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);
    

提交回复
热议问题