设为首页 加入收藏

TOP

自己定制ListView,上拉刷新和下拉刷新,加载网络图片,并且添加缓存机制。(二)
2017-10-11 17:09:32 】 浏览:10080
Tags:自己 定制 ListView 新和 下拉 刷新 加载 网络 图片 并且 添加 机制
t(8)]).execute(); 89 } 90 }); 91 } 92 93 private class MyAdapter extends ArrayAdapter<String> { 94 private LayoutInflater flater; 95 private Context context; 96 97 public MyAdapter(Context context, int resource) { 98 99 super(context, resource); 100 this.context = context; 101 flater = LayoutInflater.from(context); 102 103 } 104 105 @Override 106 public int getCount() { 107 return data.size(); 108 } 109 110 @SuppressLint("InflateParams") 111 @Override 112 public View getView(int position, View convertView, ViewGroup parent) { 113 114 if (convertView == null) 115 convertView = flater.inflate(R.layout.list, null); 116 117 ImageView iv = (ImageView) convertView.findViewById(R.id.image); 118 119 iv.setImageBitmap((Bitmap) data.get(position).get(KEY_IMAGE)); 120 121 TextView tv = (TextView) convertView.findViewById(R.id.text); 122 123 tv.setText(position + "原始数据"); 124 125 return convertView; 126 } 127 128 } 129 130 private class MyAsyncTaskTop extends AsyncTask { 131 private ProgressDialog pd; 132 @SuppressWarnings("unused") 133 private String url; 134 135 public MyAsyncTaskTop(String url) { 136 this.url = url; 137 } 138 139 @Override 140 protected void onPreExecute() { 141 // 设置加载进度条 142 pd = new ProgressDialog(activity); 143 pd.setProgressStyle(pd.STYLE_HORIZONTAL); 144 pd.setMessage("正在加载。。。"); 145 pd.show(); 146 } 147 148 @Override 149 protected Object doInBackground(Object... params) { 150 151 try { 152 // 回调加载网络的类Loadnetimage 153 Loadnetimage mLoadnetimage = new Loadnetimage(); 154 155 mLoadnetimage.SetLoadnetimageListener(new OnLoadnetimageListener() { 156 157 @SuppressWarnings("unchecked") 158 @Override 159 public void LoadnetimageListener(int count, int total) { 160 publishProgress(count, total); 161 162 } 163 }); 164 // 获取网络图片 165 Bitmap bitmap = mLoadnetimage.loadRawDataFromURL(url); 166 // 每次将图片和对应的地址放入HashMap 167 HashMap<String, Object> map = new HashMap<String, Object>(); 168 // 将新加载图片放入缓存 169 map.put(CACHE_KEY_IMAGE, bitmap); 170 map.put(CACHE_KEY_TEXT, url); 171 172 cache.add(map); 173 174 return bitmap; 175 } catch (Exception e) { 176 e.printStackTrace(); 177 } 178 179 return null; 180 181 } 182 183 @Override 184 protected void onPostExecute(Object result) { 185 addtop(result); 186 pd.dismiss(); 187 188 } 189 190 // 更新进度条 191 @Override 192 protected void onProgressUpdate(Object... values) { 193 int count = (Integer) values[0]; 194 int total = (Integer) values[1]; 195 196 pd.setMax(total); 197 pd.setProgress(count); 198 199 } 200 201 } 202 203 @SuppressWarnings("unused") 204 private class MyAsyncTaskBottom extends AsyncTask { 205 private ProgressDialog pd; 206 private String url; 207 208 public MyAsyncTaskBottom(String url) { 209 this.url = url; 210 } 211 212 @Override 213 protected void onPreExecute() { 214 // 设置进度条 215 pd = new ProgressDialog(activity); 216 // 样式 217 pd.setProgressStyle(pd.STYLE_HORIZONTAL); 218 pd.setMessage("正在加载。。。"); 219 pd.show(); 220 221 } 222 223 @Override 224 protected Object doInBackground(Object... params) { 225 // 回调加载网络的类Loadnetimag
首页 上一页 1 2 3 4 5 下一页 尾页 2/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇自己定制ListView,上拉刷新和下.. 下一篇Material Design:CollapsingTool..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目