0

如果互联网可用,我会从数据库中获取图像 url 它的自动显示图像但是没有可用的互联网不显示默认图像告诉我为什么我的问题是当没有可用的互联网时为什么不 gridview 在屏幕上加载 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>
4

0 回答 0