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

      

  • 相关阅读:
    常见概念
    网站扒取
    图书管理系统易错点整理
    CSIC_716_2020104【Django入门---静态文件、request对象方法、ORM增删改查】
    CSIC_716_2020103【Django入门---HttpResponse、render、redirect】
    CSIC_716_2020102【前端框架Bootstrap】
    CSIC_716_2020101【???】
    CSIC_716_20191231【jQuery基础入门】
    CSIC_716_20191230【前端的BOM与DOM】
    ss
  • 原文地址:https://www.cnblogs.com/sixrain/p/4969248.html
Copyright © 2011-2022 走看看