Android将值从活动传递到适配器 [英] Android pass value from activity to adapter
本文介绍了Android将值从活动传递到适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将变量从活动传递到适配器.
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;
}
我的活动看起来像这样
newadapter = new SampleAdapter(this);
newadapter.setId(Login_uuid_value);
给我错误SampleAdapter无法应用于活动.
Gives me error SampleAdapter cannot be applied to the activity.
推荐答案
只需将值添加到构造函数中.
Simply add the values to the constructor.
public SimpleAdapter(Activity context, ArrayList<SimpleBeans> data, String mystring, int myInt){
//use datas here
}
并像使用它
myAdapter = new SimpleAdapter(this, data, myString, myInt);
当然,您可以设置所需的所有数据,例如.
Obiouvsly you can set all the datas you want, mine were some examples.
在您的情况下,您只需要将arrayList添加到构造函数中即可.
In your case you simply need to add the arrayList to the constructor.
myAdapter = new SimpleAdapter(this, myArrayList);
这篇关于Android将值从活动传递到适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文