当互联网不可用时,gridview不显示默认图像

时间:2013-11-07 06:55:22

标签: android

我正在从数据库获取图像网址,如果互联网可用其自动显示图像,但是没有可用的互联网不显示默认图像,为什么我的问题是什么时候没有互联网可用为什么网格视图在屏幕上加载ic_launcher图像

      ExpandableHeightGridView gridview;
       CategoryListAdapter3 cla;
        static ArrayList<String> Category_name = new ArrayList<String>();
static ArrayList<String> Category_image = new ArrayList<String>();


       JSONArray jArray = new JSONArray(allergen);
    //
    for (int i = 0; i < jArray.length(); i++) {
        JSONObject object = jArray.getJSONObject(i);


        Category_ID.add((long) i);
        Category_name.add(object.getString("name"));  /image name
        Category_image.add(object.getString("image")); // image url

    }

                gridview= (ExpandableHeightGridView) findViewById(R.id.gridview) 
                        gridview.setAdapter(cla);




   public class CategoryListAdapter3 extends BaseAdapter {

private Activity activity;


private AQuery androidAQuery;


public CategoryListAdapter3(Activity act) {
    this.activity = act;

}

public int getCount() {
    // TODO Auto-generated method stub
    return fifthscreen.Category_ID.size();
}

public Object getItem(int position) {
    // TODO Auto-generated method stub
    return position;
}

 public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    ViewHolder holder;
    androidAQuery = new AQuery(getcontext());
    if(convertView == null){
        LayoutInflater inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.viewitem2, null);
        holder = new ViewHolder();

        convertView.setTag(holder);
    }else{
        holder = (ViewHolder) convertView.getTag();
    }


    holder.txtText = (TextView) convertView.findViewById(R.id.title2);
    holder.imgThumb = (ImageView) convertView.findViewById(R.id.image2);

    holder.txtText.setText(fifthscreen.Category_name.get(position));


  androidAQuery.id(holder.imgThumb).image(fifthscreen.Category_image.get(position), true, true);

    return convertView;
}
private Activity getcontext() {
    // TODO Auto-generated method stub
    return null;
}
static class ViewHolder {
    TextView txtText;
    ImageView imgThumb;
}

 }


  //viewitem2.xml//////

       <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"

  >

 <ImageView
android:id="@+id/image2"
   android:layout_width="wrap_content"
 android:layout_height="70dp"
  android:scaleType="fitXY"
 android:padding="5dp"

   android:layout_marginLeft="5dp"
  android:layout_marginRight="5dp"

  android:src="@drawable/ic_launcher" 
/>

<TextView
android:id="@+id/title2"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:textColor="#000"
android:paddingTop="10dp"


android:gravity="center_horizontal"
/>



   </LinearLayout>

0 个答案:

没有答案