我必須在我的android應用程序的列表視圖中顯示來自mysql數據庫的數據。我已經成功解析了文本數據並將其顯示在自定義列表視圖中,但圖像未被解析並顯示在列表中。我曾嘗試使用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);
}
嘗試但它沒有工作... – Divyang