栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在ListFragment中使用JSON获取图像?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在ListFragment中使用JSON获取图像?

尝试使用自定义适配器的AndroidQuery:

public class CustomAdapter extends baseAdapter {    private Context context;    private ArrayList<HashMap<String,String>> listData;    private AQuery aQuery;    private static final String TAG_NAME="name";    private static final String TAG_PROFILE="profile_id";    private static final String TAG_IMAGE="image";    private static final String TAG_CAST="cast";    private static final String TAG_AGE="age";    private static final String TAG_LOCATION="location";    public CustomAdapter(Context context,ArrayList<HashMap<String,String>> listData) {        this.context = context;        this.listData=listData;        aQuery = new AQuery(this.context);    }    @Override    public int getCount() {        return listData.size();    }    @Override    public Object getItem(int position) {        return listData.get(position);    }    @Override    public long getItemId(int position) {        return position;    }    @Override    public View getView(final int position, View convertView, ViewGroup parent) {        ViewHolder holder;        if (convertView == null) { holder = new ViewHolder(); convertView = LayoutInflater.from(context).inflate(R.layout.list_item, null); holder.propic = (ImageView) convertView.findViewById(R.id.propic); holder.txtproname = (TextView) convertView.findViewById(R.id.txtproname); holder.txtproid = (TextView) convertView.findViewById(R.id.txtproid); holder.txtprofilecast = (TextView) convertView.findViewById(R.id.txtprofilecast); holder.txtprofileage = (TextView) convertView.findViewById(R.id.txtprofileage); holder.txtprofileplace = (TextView) convertView.findViewById(R.id.txtprofileplace); convertView.setTag(holder);        }else{ holder = (ViewHolder) convertView.getTag();        }        holder.txtproname.setText(listData.get(position).get(TAG_NAME));        holder.txtproid.setText(listData.get(position).get(TAG_PROFILE));        holder.txtprofilecast.setText(listData.get(position).get(TAG_CAST));        holder.txtprofileage.setText(listData.get(position).get(TAG_AGE));        holder.txtprofileplace.setText(listData.get(position).get(TAG_LOCATION));        aQuery.id(holder.propic).image(listData.get(position).get(TAG_IMAGE),true,true,0,R.drawable.ic_launcher);        // image parameter : 1 : memory cache,2:file cache,3:target width,4:fallback image        return convertView;    }    class ViewHolder{        ImageView propic;        TextView txtproname;        TextView txtproid;        TextView txtprofilecast;        TextView txtprofileage;        TextView txtprofileplace;    }}

如何将适配器设置为ListView:

CustomAdapter adapter = new CustomAdapter(getActivity(),aList);setListAdapter(adapter);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/449305.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号