在static中摘引SimpleAdapter
在static中引用SimpleAdapter
在静态类中引用SimpleAdapter在第二个参数引用应该怎么写?
------解决思路----------------------
第一个参数错误,应该写成this.getActivity()
public static class DummySectionFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Http hp=new Http();
SimpleAdapter adapter = new SimpleAdapter(this,hp.getData(),R.layout.base,
new String[]{"title","info","img"},
new int[]{R.id.title,R.id.info,R.id.img});
}
}
public class Http {
public Bitmap getImage(String url){
URL imgeUrl=null;
Bitmap bitmap=null;
try{
imgeUrl=new URL(url);
}
catch (MalformedURLException e) {
Log.e("url error","url = "+url);
}
try{
HttpURLConnection conn = (HttpURLConnection)imgeUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is =conn.getInputStream();
BufferedInputStream bis=new BufferedInputStream(is);
bitmap=BitmapFactory.decodeStream(bis);
bis.close();
is.close();
}catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
/**
* 解析多个数据的Json
*/
public List<Map<String, Object>> getData() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Bitmap bitmap1=getImage("http://www.abc.com/img/87.jpg");
Bitmap bitmap2=getImage("http://www.abc.com/img/41.jpg");
Bitmap bitmap3=getImage("http://www.abc.com/img/1058.jpg");
BitmapDrawable bmp1=new BitmapDrawable(bitmap1);
BitmapDrawable bmp2=new BitmapDrawable(bitmap2);
BitmapDrawable bmp3=new BitmapDrawable(bitmap3);
Map<String, Object> map = new HashMap<String, Object>();
map.put("title", "G1");
map.put("info", "google 1");
map.put("img", bmp1);
list.add(map);
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put("title", "G2");
map2.put("info", "google 2");
map2.put("img", bmp2);
list.add(map2);
Map<String, Object> map3 = new HashMap<String, Object>();
map3.put("title", "G3");
map3.put("info", "google 3");
map3.put("img", bmp3);
list.add(map3);
return list;
}
}
在静态类中引用SimpleAdapter在第二个参数引用应该怎么写?
------解决思路----------------------
第一个参数错误,应该写成this.getActivity()