zoukankan      html  css  js  c++  java
  • 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);
    	}
    }
    

      

  • 相关阅读:
    107.JsonResponse
    106.HttpResponse对象详解
    前端学习笔记系列一:2 Vue的单文件组件
    前端学习笔记系列一:1.export default / export const
    @vue-cli的安装及vue项目创建
    Github版本控制系统
    C# 篇基础知识11——泛型和集合
    C# 篇基础知识10——多线程
    C# 篇基础知识9——特性、程序集和反射
    C# 篇基础知识8——正则表达式
  • 原文地址:https://www.cnblogs.com/sixrain/p/4969248.html
Copyright © 2011-2022 走看看