当前位置:编程学习 > wap >>

在static中引用SimpleAdapter


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在第二个参数引用应该怎么写? --------------------编程问答-------------------- 为什么实例化了Http还是 在引用getData()出错? --------------------编程问答--------------------
引用 1 楼 sjmhai110 的回复:
为什么实例化了Http还是 在引用getData()出错?
那就是getData出错了咯
这种问题其实可以自己先断点看看在问吧,知道getData具体哪行出错了再问吧 --------------------编程问答--------------------
引用 2 楼 q445697127 的回复:
引用 1 楼 sjmhai110 的回复:为什么实例化了Http还是 在引用getData()出错?那就是getData出错了咯
这种问题其实可以自己先断点看看在问吧,知道getData具体哪行出错了再问吧

getData没问题。。。是编译器检测的错误。
The constructor SimpleAdapter(MainActivity.DummySectionFragment, List<Map<String,Object>>, int, String[], int[]) is undefined --------------------编程问答-------------------- 第一个参数错误,应该写成this.getActivity()
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,