gpt4 book ai didi

android - 将图像从数据库显示并解析到 ListView

转载 作者:行者123 更新时间:2023-11-30 01:22:29 24 4
gpt4 key购买 nike

我必须在我的 Android 应用程序的 ListView 中显示来自 mysql 数据库的数据。我已成功解析文本数据并将其显示在自定义 ListView 中,但图像未被解析并显示在列表中。我尝试过使用imageloader、文件缓存、内存缓存,但仍然没有成功。

如果有人知道缺少什么或应该添加什么,任何帮助将不胜感激。

public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
TextView tourname;
TextView duration;
ImageView flag;

inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View itemView = inflater.inflate(R.layout.list_row1, parent, false);
// Get the position from the results


// Locate the TextViews in listview_item.xml
tourname = (TextView) itemView.findViewById(R.id.themeTourList_title);
duration = (TextView) itemView.findViewById(R.id.themeTourList_price);
// Locate the ImageView in listview_item.xml
flag = (ImageView) itemView.findViewById(R.id.themeTourList_image);

// Capture position and set results to the TextViews
try
{
tourname.setText(mJSONArray.getJSONObject(position).getString("tour_name"));
duration.setText(""+mJSONArray.getJSONObject(position).getString("nights")+" Nights - "+mJSONArray.getJSONObject(position).getString("days")+" Days");
try{
URL url = new URL("www.futurolicht.com/"+mJSONArray.getJSONObject(position).getString("pic"));
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)(url).getContent());
flag.setImageBitmap(bitmap);
}

最佳答案

尝试使用以下方法下载图片:

URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);

关于android - 将图像从数据库显示并解析到 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18400036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com