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);
	}
}

  

 

posted @ 2015-11-16 16:20  梦和远方  阅读(188)  评论(0编辑  收藏  举报