我正在尝试调用LazyAdapter
构造函数来设置ListView
. 我总是看到red line
有人new LazyAdapter(this, mStrings);
要求解决这个问题。我不确定我应该在此处添加什么来代替它,以便它可以开始工作。当我尝试用getApplicationContext
then 替换它时,我总是得到错误ClassCastException
。有什么想法我需要添加的this
吗?
@Override
protected void onPostExecute(ArrayList<User> response) {
if (response!=null) {
adapter=new LazyAdapter(this, mStrings);
listView.setAdapter(adapter);
}
for(User user : response){
//Doing Some Stuff Here
}
}
LazyAdapter
构造函数是这样的-
public LazyAdapter(Activity a, String[] d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
更新:-
我的 LazyAdapter 完整代码-
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private String[] data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public LazyAdapter(Activity a, String[] d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.item, null);
TextView text=(TextView)vi.findViewById(R.id.text);;
ImageView image=(ImageView)vi.findViewById(R.id.image);
text.setText("item "+position);
imageLoader.DisplayImage(data[position], image);
return vi;
}
}