8.专题

SubjectProtocol

  1. public class SubjectProtocol extends BaseProtocol<List<SubjectInfo>>{ @Override public List<SubjectInfo> paserJson(String json) { List<SubjectInfo> subjectInfos=new ArrayList<SubjectInfo>(); try { JSONArray jsonArray=new JSONArray(json); for(int i=0;i<jsonArray.length();i++){ JSONObject jsonObject = jsonArray.getJSONObject(i); String des=jsonObject.getString("des"); String url = jsonObject.getString("url"); SubjectInfo info=new SubjectInfo(des, url); subjectInfos.add(info); } return subjectInfos; } catch (JSONException e) { e.printStackTrace(); return null; } } @Override public String getKey() { return "subject"; } }

SubjectFragment

public class SubjectFragment extends BaseFragment {
	private List<SubjectInfo> datas;
	@Override
	public View createSuccessView() {
		ListView listView=new ListView(UiUtils.getContext());
		listView.setAdapter(new SubjectAdapter());
		return listView;
	}
	private class SubjectAdapter extends BaseAdapter{
		@Override
		public int getCount() {
			return datas.size();
		}
		@Override
		public Object getItem(int position) {
			return datas.get(position);
		}
		@Override
		public long getItemId(int position) {
			return position;
		}
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			View view;
			ViewHolder holder;
			if(convertView!=null){
				view=convertView;
				holder=(ViewHolder) view.getTag();
			}else{
				view=UiUtils.inflate(R.layout.item_subject);
				holder=new ViewHolder();
				holder.item_icon=(ImageView) view.findViewById(R.id.item_icon);
				holder.item_txt=(TextView) view.findViewById(R.id.item_txt);
				view.setTag(holder);
			}
			SubjectInfo info=datas.get(position);
			holder.item_txt.setText(info.getDes());
			bitmapUtils.display(holder.item_icon, HttpHelper.URL+"image?name="+info.getUrl());
			return view;
		}
		
	}
	class ViewHolder{
		ImageView item_icon;
		TextView item_txt;
	}
	@Override
	protected LoadResult load() {
		SubjectProtocol protocol=new SubjectProtocol();
		datas = protocol.load(0);
		return checkData(datas);
	}
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

扫码关注云+社区

领取腾讯云代金券