2012-07-20 75 views
0

我的老闆說我要使用Android查詢負載ListView中的圖像異步的,我發現這個網站:http://code.google.com/p/android-query/wiki/ImageLoading 但是我試着用:(安卓)從URL

aq.id(R.id.image1).image("http://www.vikispot.com/z/images/vikispot/android-w.png"); 

在我的代碼,但我得到這個錯誤: 「aq不能解決」 我必須做什麼來初始化aq,我必須導入一些庫?

這是我的列表視圖適配器: public static class ListViewAdapterWall extends BaseAdapter {0}私有LayoutInflater mInflater;

public ListViewAdapterWall(Context context) { 

     mInflater = LayoutInflater.from(context); 

    } 

    public int getCount() { 
     return ListviewContentWall.size(); 
    } 

    public Object getItem(int position) { 
     return position; 
    } 

    public long getItemId(int position) { 
     return position; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 

     ListContent holder; 

     if (convertView == null) { 
      convertView = mInflater.inflate(R.layout.listviewinflate, null); 

      holder = new ListContent(); 
      holder.wallImage = (ImageView) convertView 
        .findViewById(R.id.wallImage1); 
      holder.wallButton = (ImageButton) convertView 
        .findViewById(R.id.wallButton1); 


      convertView.setTag(holder); 
     } else { 

      holder = (ListContent) convertView.getTag(); 
     } 

     AQuery aq = new AQuery(convertView); 

     aq.id(R.id.wallImage1).image("http://www.vikispot.com/z/images/vikispot/android-w.png"); 
     //holder.wallImage.setBackgroundDrawable(ListviewContentWall.get(position)); 
     //holder.wallButton.setBackgroundDrawable(ListviewContentWall.get(position)); 
     //holder.text2.setText(ListviewContent2.get(position)); 

     return convertView; 
    } 
+0

嘗試用'AQuery含水=新AQuery(上下文);' – 2012-07-20 06:26:30

回答

0

我不得不在互聯網上搜索的lib上:Android的查詢0.22.10.jar並把它放在我的libs文件夾,它的工作

1

AQuery是圍繞視圖的包裝。

初始化它如下

AQuery aq = new AQuery(imageView); 

這個片段是你提到的同一頁!

+0

同樣認爲與ImageView的,上下文或convertView。該行得到這個錯誤: 多個標記在該行 \t - AQuery不能被解析爲一個類型 \t - AQuery不能被解析爲一個類型 – 2012-07-20 06:37:05

+0

你添加庫正確呢? – 2012-07-20 06:42:54

+0

我必須添加什麼庫?他們不是自己添加嗎?或者至少他應該在錯誤中提示我:添加import.dontknowname? – 2012-07-20 06:52:49

0

安卓查詢ImageLoading具有再循環()方法。從android_query

的Javadoc說,再循環()方法作爲

public T recycle(View root) Recycle this AQuery object. The method is designed to avoid recreating an AQuery object repeatedly, such as when in list adapter getView method.

Parameters:

root - The new root of the recycled AQuery.

Returns:

self

,這裏是源調整上述方法。

AQuery listAq = new AQuery(this); 

public ListViewAdapterWall(Context context) { 
    mInflater = LayoutInflater.from(context); 
} 

public int getCount() { 
    return ListviewContentWall.size(); 
} 

public Object getItem(int position) { 
    return position; 
} 

public long getItemId(int position) { 
    return position; 
} 

public View getView(int position, View convertView, ViewGroup parent) { 

    ListContent holder; 

    if (convertView == null) { 
     convertView = mInflater.inflate(R.layout.listviewinflate, null); 

     holder = new ListContent(); 
     holder.wallImage = (ImageView) convertView 
       .findViewById(R.id.wallImage1); 
     holder.wallButton = (ImageButton) convertView 
       .findViewById(R.id.wallButton1); 


     convertView.setTag(holder); 
    } else { 

     holder = (ListContent) convertView.getTag(); 
    } 

    AQuery aq = listAq.recycle(convertView); 

    aq.id(R.id.wallImage1).image("http://www.vikispot.com/z/images/vikispot/android-w.png"); 
    //holder.wallImage.setBackgroundDrawable(ListviewContentWall.get(position)); 
    //holder.wallButton.setBackgroundDrawable(ListviewContentWall.get(position)); 
    //holder.text2.setText(ListviewContent2.get(position)); 

    return convertView; 
}