在android中Imageview不能在片段中工作

时间:2014-05-08 11:32:00

标签: java android android-fragments uiimageview imageview

我使用textview和imageview在gridview中填充它但textview我可以从数据库中检索但我不能为imageview做同样的事情

请帮我工作imageview

class ImageAdapter extends BaseAdapter {
private Context context;
public ImageView imageView;
private ArrayList<HashMap<String, String>> MyArr = new ArrayList<HashMap<String, String>>();

public ImageAdapter(Context c,ArrayList&gt; list){
        context = c;

    MyArr = list;
}
public int getCount() {

    return MyArr.size();
}

public Object getItem(int position) {

    return position;
}

public long getItemId(int position) {

    return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.store_home_gridview_row, null); 
    }

    TextView tv_title = (TextView) convertView.findViewById(R.id.textview_name);
    tv_title.setText("Title:"+MyArr.get(position).get("name"));

    TextView tv_artist = (TextView) convertView.findViewById(R.id.textview_artist);
    tv_artist.setText("Artist:"+MyArr.get(position).get("artist"));

    TextView tv_duration = (TextView) convertView.findViewById(R.id.textview_price);
    tv_duration.setText("Price:"+MyArr.get(position).get("price"));

    String abc = (MyArr.get(position).get("image")); // returns null 
    String abcd = "http://192.168.1.132/images/products/"+abc; // returns null

    imageView = (ImageView) convertView.findViewById(R.id.imageView1);
    try
    {
        URL url3 = null;
        try {
            url3 = new URL(abcd);// url returns from above 
            } catch (Exception e) {

            e.printStackTrace();
        }
        Bitmap bmp = BitmapFactory.decodeStream(url3.openConnection().getInputStream()); //image is not getting populated 
        imageView.setImageBitmap(bmp);
    }
    catch(Exception par)
    {
        imageView.setImageResource(android.R.drawable.ic_menu_report_image);
    }
    return convertView;         
}}

提前致谢

0 个答案:

没有答案