快哭了,救救孩子
听了你们的意见我开了两次AsynTask,我没有选择把图片存入SD卡,我是想直接在第二个AsynTask实现图片的设置,然后我这里就变成最后一个viewHolder轮播图片了,前面五个不显示..... package com.example.group_buying; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; public class menuAdapter extends BaseAdapter { List<LessonResult.LessonInfo> mLessonInfos; private Context mContext; Bitmap bitmapc=null; ViewHolder viewHolder; public menuAdapter(Context context,List<LessonResult.LessonInfo> infos) { mLessonInfos=infos; mContext=context; } @Override public int getCount() { return mLessonInfos.size(); } @Override public Object getItem(int position) { return mLessonInfos.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { viewHolder=new ViewHolder(); if(convertView==null){ LayoutInflater layoutInflater= (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE); convertView=layoutInflater.inflate(R.layout.menu_listview,null); viewHolder.food_View=convertView.findViewById(R.id.food); viewHolder.food_Name=convertView.findViewById(R.id.food_name); viewHolder.context=convertView.findViewById(R.id.context); viewHolder.food_price=convertView.findViewById(R.id.price); viewHolder.food_discount=convertView.findViewById(R.id.discount); viewHolder.sale=convertView.findViewById(R.id.sale); convertView.setTag(viewHolder); }else{ viewHolder= (ViewHolder) convertView.getTag(); } String url=mLessonInfos.get(position).getPictureurl(); new RequestDataAsyncTaskSecond().execute(url); viewHolder.food_Name.setText(mLessonInfos.get(position).getFoodname()); viewHolder.context.setText(mLessonInfos.get(position).getDescription()); viewHolder.food_price.setText(mLessonInfos.get(position).getPrice()); viewHolder.food_discount.setText(mLessonInfos.get(position).getAction()); viewHolder.sale.setText(mLessonInfos.get(position).getCount()); return convertView; } public class ViewHolder{ public ImageView food_View; public TextView food_Name; public TextView context; public TextView food_price; public TextView food_discount; public TextView sale; } public class RequestDataAsyncTaskSecond extends AsyncTask<String,Void,Bitmap> { String str=null; @Override protected void onPreExecute() { super.onPreExecute(); // } protected Bitmap doInBackground(String... path) { str=path[0]; try { URL url = new URL(str); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); conn.setRequestMethod("GET"); if (conn.getResponseCode() == 200) { InputStream inputStream = conn.getInputStream(); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); return bitmap; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } protected void onPostExecute(Bitmap bitmap) { viewHolder.food_View.setImageBitmap(bitmap); } } }
18
收起
正在回答 回答被采纳积分+1
1回答
慕工程6972752
2019-11-11 16:56:57
啊啊啊啊,我解决了,落泪了,
2.Android 网络操作与流行框架
- 参与学习 人
- 提交作业 220 份
- 解答问题 1800 个
本阶段是联网及数据处理的必备技能。课程从网络基础知识到线程间协同工作、异步下载处理;从文件存储、到轻量级数据库SQLite的使用;最后利用最流程的第三方框架助你快速开发企业级APP。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星