我正在尝试将 JSON 数据(图像 url)解析为 gridView。我能够从 JSON 中获取数据,但是当我尝试将 simpleAdapter 设置为在 gridView 上显示它们时,我得到了一个红旗说明:
构造函数 SimpleAdapter(SalesFragment, List>, int, String[], int[]) 未定义。
我用谷歌搜索但找不到任何解决方案。请帮忙...
销售片段.java
public class SalesFragment extends Fragment {
GridView gridView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View gv = inflater.inflate(R.layout.hot_sales, null);
gridView = (GridView) gv.findViewById(R.id.grid_view);
//gridView.setAdapter(new ImageAdapter(this, getActivity()));
bindGridview();
return gv;
}
public void bindGridview() {
new MyAsyncTask(getActivity(),gridView).execute("");
}
class MyAsyncTask extends AsyncTask<String, String, String> {
GridView mGridView;
Activity mContext;
Response response;
public MyAsyncTask(Activity context,GridView gview) {
this.mGridView=gview;
this.mContext=context;
}
protected String doInBackground(String... params) {
try{
// here getting JSON data using GSON
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (@SuppressWarnings("hiding") IOException e){
e.printStackTrace();
}
}else{
System.out.println("Error");
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
List<HashMap<String,String>> aList1 = new ArrayList<HashMap<String,String>>();
for(Sales sales : this.response.sales){
HashMap<String, String> hm = new HashMap<String,String>();
if (sales.getCategories1().contains("12")){
//getting the data
}
aList1.add(hm);
}
}
SimpleAdapter adapter = new SimpleAdapter(SalesFragment.this, aList1,
R.layout.grid_sales, new String[] { "shop_image"},new int[] { R.id.sale_image });
// updating gridview
gridView.setAdapter(adapter);
}
}