我必须在我的 android 应用程序的列表视图中显示来自 mysql 数据库的数据。我已成功解析文本数据并将其显示在自定义列表视图中,但图像没有被解析并显示在列表中。我尝试过使用图像加载器、文件缓存、内存缓存,但仍然没有成功。
如果有人对缺少什么或应该添加什么有任何想法,我们将不胜感激。
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);
}