2012-01-12 34 views
0

加載圖片我用延遲加載在我的ListView關於Android LazyAdapter .... ListView中

加載圖像和圖像從網站

我解析圖像的URL到字符串數組中

,並設置LazyAdapter這樣

adapter=new LazyAdapter(this, aStrArray); 
      list.setAdapter(adapter); 

我敢肯定,對aStrArray是沒有問題的。

(我以前登錄的話)

但是ListView控件只加載第一個圖像...

這是爲什麼?

這裏是我的代碼

public class BBtest08Activity extends Activity { 
/** Called when the activity is first created. */ 
ListView list; 
LazyAdapter adapter; 
String aStr; 
String aStrArray[]; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    list=(ListView)findViewById(R.id.list); 
    try { 
     executeHttpGet(); 
    } catch (Exception e) { 
     Log.i("bird","parser failed"); 
     e.printStackTrace(); 
    } 
    Button b=(Button)findViewById(R.id.button1); 
    b.setOnClickListener(listener); 
} 
@Override 
public void onDestroy() 
{ 
    list.setAdapter(null); 
    super.onDestroy(); 
} 

public OnClickListener listener=new OnClickListener(){ 
    @Override 
    public void onClick(View arg0) { 
     adapter.imageLoader.clearCache(); 
     adapter.notifyDataSetChanged(); 
    } 
}; 
public void executeHttpGet() throws Exception { 
    try { 
    HttpClient client = new DefaultHttpClient(); 
    HttpGet request = new HttpGet("http://test.mobibon.com.tw/MovieGoTest/GetMovies.js"); 
    HttpResponse response = client.execute(request); 
    String retSrc = EntityUtils.toString(response.getEntity(),"utf-8"); 
    retSrc = retSrc.substring(1);//there a space in the very first 
     JSONObject obj = new JSONObject(retSrc); 
     JSONArray movieArray = obj.getJSONArray("movies"); 
     for(int i = 0;i < movieArray.length(); i++) 
     { 
     JSONObject movie_data = movieArray.getJSONObject(i); 
     aStr = aStr+movie_data.getString("imageUrl")+","; 
     aStrArray = aStr.split(","); 
     } 
     } finally { 
      adapter=new LazyAdapter(this, aStrArray); 
      list.setAdapter(adapter); 
     } 
     } 

}

感謝您的幫助!

您也可以用中文回答我,謝謝您

P.S.

從筆者延遲加載器是這樣的---

public class MainActivity extends Activity { 

ListView list; 
LazyAdapter adapter; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    list=(ListView)findViewById(R.id.list); 
    adapter=new LazyAdapter(this, mStrings); 
    list.setAdapter(adapter); 

    Button b=(Button)findViewById(R.id.button1); 
    b.setOnClickListener(listener); 
} 

@Override 
public void onDestroy() 
{ 
    list.setAdapter(null); 
    super.onDestroy(); 
} 

public OnClickListener listener=new OnClickListener(){ 
    @Override 
    public void onClick(View arg0) { 
     adapter.imageLoader.clearCache(); 
     adapter.notifyDataSetChanged(); 
    } 
}; 

private String[] mStrings={ 
     "http://test.mobibon.com.tw/MovieGoTest/Pics/pl_fmen7122923814_s.jpg", 
     "http://test.mobibon.com.tw/MovieGoTest/Pics/pl_fmen7122923814_s.jpg", 
     "http://a3.twimg.com/profile_images/121630227/Droid_normal.jpg", 
     "http://a1.twimg.com/profile_images/957149154/twitterhalf_normal.jpg", 
     "http://a1.twimg.com/profile_images/97470808/icon_normal.png", 
     "http://a3.twimg.com/profile_images/511790713/AG.png", 
     "http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png", 
     "http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png", 
     "http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg", 
     "http://a1.twimg.com/profile_images/349012784/android_logo_small_normal.jpg", 
     "http://a1.twimg.com/profile_images/841338368/ea-twitter-icon.png", 
     "http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png", 
     "http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png", 
     "http://a1.twimg.com/profile_images/850960042/elandroidelibre-logo_300x300_normal.jpg", 
     "http://a1.twimg.com/profile_images/655119538/andbook.png", 
     "http://a3.twimg.com/profile_images/768060227/ap4u_normal.jpg", 
     "http://a1.twimg.com/profile_images/74724754/android_logo_normal.png", 
     "http://a3.twimg.com/profile_images/681537837/SmallAvatarx150_normal.png", 
     "http://a1.twimg.com/profile_images/63737974/2008-11-06_1637_normal.png", 
     "http://a3.twimg.com/profile_images/548410609/icon_8_73.png", 
     "http://a1.twimg.com/profile_images/612232882/nexusoneavatar_normal.jpg", 
     "http://a1.twimg.com/profile_images/213722080/Bugdroid-phone_normal.png", 
     "http://a1.twimg.com/profile_images/645523828/OT_icon_090918_android_normal.png", 
     "http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png", 
     "http://a3.twimg.com/profile_images/77641093/AndroidPlanet.png", 
     "http://a1.twimg.com/profile_images/850960042/elandroidelibre-logo_300x300_normal.jpg", 
     "http://a1.twimg.com/profile_images/655119538/andbook_normal.png", 
     "http://a3.twimg.com/profile_images/511790713/AG_normal.png", 
     "http://a3.twimg.com/profile_images/956404323/androinica-avatar.png", 
     "http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png", 
     "http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg", 
     "http://a1.twimg.com/profile_images/349012784/android_logo_small_normal.jpg", 
     "http://a1.twimg.com/profile_images/841338368/ea-twitter-icon_normal.png", 
     "http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png", 
     "http://a3.twimg.com/profile_images/77641093/AndroidPlanet.png", 
     "http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png", 
     "http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png", 
     "http://a1.twimg.com/profile_images/850960042/elandroidelibre-logo_300x300.jpg", 
     "http://a1.twimg.com/profile_images/655119538/andbook_normal.png", 
     "http://a3.twimg.com/profile_images/511790713/AG_normal.png", 
     "http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png", 
     "http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png", 
     "http://a3.twimg.com/profile_images/121630227/Droid.jpg", 
     "http://a1.twimg.com/profile_images/957149154/twitterhalf_normal.jpg", 
     "http://a1.twimg.com/profile_images/97470808/icon_normal.png", 
     "http://a3.twimg.com/profile_images/511790713/AG_normal.png", 
     "http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png", 
     "http://a1.twimg.com/profile_images/909231146/Android_Biz_Man.png", 
     "http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg", 
     "http://a1.twimg.com/profile_images/349012784/android_logo_small_normal.jpg", 
     "http://a1.twimg.com/profile_images/841338368/ea-twitter-icon_normal.png", 
     "http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png", 
     "http://a3.twimg.com/profile_images/77641093/AndroidPlanet.png", 
     "http://a3.twimg.com/profile_images/670625317/aam-logo-v3-twitter_normal.png", 
     "http://a3.twimg.com/profile_images/740897825/AndroidCast-350_normal.png", 
     "http://a3.twimg.com/profile_images/121630227/Droid_normal.jpg", 
     "http://a1.twimg.com/profile_images/957149154/twitterhalf_normal.jpg", 
     "http://a1.twimg.com/profile_images/97470808/icon.png", 
     "http://a3.twimg.com/profile_images/511790713/AG_normal.png", 
     "http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png", 
     "http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png", 
     "http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg", 
     "http://a1.twimg.com/profile_images/349012784/android_logo_small_normal.jpg", 
     "http://a1.twimg.com/profile_images/841338368/ea-twitter-icon.png", 
     "http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png", 
     "http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png", 
     "http://a1.twimg.com/profile_images/850960042/elandroidelibre-logo_300x300_normal.jpg", 
     "http://a1.twimg.com/profile_images/655119538/andbook_normal.png", 
     "http://a3.twimg.com/profile_images/768060227/ap4u_normal.jpg", 
     "http://a1.twimg.com/profile_images/74724754/android_logo.png", 
     "http://a3.twimg.com/profile_images/681537837/SmallAvatarx150_normal.png", 
     "http://a1.twimg.com/profile_images/63737974/2008-11-06_1637_normal.png", 
     "http://a3.twimg.com/profile_images/548410609/icon_8_73_normal.png", 
     "http://a1.twimg.com/profile_images/612232882/nexusoneavatar_normal.jpg", 
     "http://a1.twimg.com/profile_images/213722080/Bugdroid-phone_normal.png", 
     "http://a1.twimg.com/profile_images/645523828/OT_icon_090918_android.png", 
     "http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png", 
     "http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png", 
     "http://a1.twimg.com/profile_images/850960042/elandroidelibre-logo_300x300_normal.jpg", 
     "http://a1.twimg.com/profile_images/655119538/andbook.png", 
     "http://a3.twimg.com/profile_images/511790713/AG_normal.png", 
     "http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png", 
     "http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png", 
     "http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg", 
     "http://a1.twimg.com/profile_images/349012784/android_logo_small_normal.jpg", 
     "http://a1.twimg.com/profile_images/841338368/ea-twitter-icon.png", 
     "http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png", 
     "http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png", 
     "http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png", 
     "http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png", 
     "http://a1.twimg.com/profile_images/850960042/elandroidelibre-logo_300x300_normal.jpg", 
     "http://a1.twimg.com/profile_images/655119538/andbook_normal.png", 
     "http://a3.twimg.com/profile_images/511790713/AG_normal.png", 
     "http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png", 
     "http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png", 
     "http://a3.twimg.com/profile_images/121630227/Droid_normal.jpg", 
     "http://a1.twimg.com/profile_images/957149154/twitterhalf.jpg", 
     "http://a1.twimg.com/profile_images/97470808/icon_normal.png", 
     "http://a3.twimg.com/profile_images/511790713/AG_normal.png", 
     "http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png", 
     "http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png", 
     "http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg", 
     "http://a1.twimg.com/profile_images/349012784/android_logo_small.jpg", 
     "http://a1.twimg.com/profile_images/841338368/ea-twitter-icon_normal.png", 
     "http://a3.twimg.com/profile_images/64827024/android-wallpaper6_2560x160_normal.png", 
     "http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png" 
}; 
} 

回答

0

什麼是更重要的是LazyAdapter內getView功能,您應該記錄的getView函數裏面,看看有什麼網址實際上是由設置ImageView的。

此外,你爲什麼要分裂aStr每個循環?您應該在循環內將新URL添加到aStr,並在for循環之後將其分割成數組。

+0

我想了解你告訴我什麼.... 感謝您的幫助.. – bbbbbird1 2012-01-12 03:08:30

+0

順便說一句,如果你想中國的回答,您可以通過電子郵件 – reTs 2012-01-12 03:11:38

+0

親自與我聯繫你是臺灣人..? 我想給你打電話...... BTW ...的LazyAdapter內getView功能讓每一個網址... 但只顯示第一個圖像.... – bbbbbird1 2012-01-12 03:13:50