2013-12-16 128 views
0

我有一個列表視圖,顯示從互聯網上下載,並有如下列表視圖中的每一行的自定義版面圖:的ListView不顯示圖像正確

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="#00f" 
    > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:background="@drawable/wish" 
     android:gravity="center_vertical|center_horizontal" 
     android:paddingBottom="5dp" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp" 
     android:paddingTop="5dp" 
     android:text="" /> 
    </LinearLayout> 

我getview方法爲初級講座:

public View getView(int arg0, View arg1, ViewGroup arg2) 
{ 
    // TODO Auto-generated method stub 

    View v; 

    final TextView tv; 

    if(arg1 == null) 
    { // if it's not recycled, initialize some attributes 
     LayoutInflater lf = (LayoutInflater) conn.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     v = lf.inflate(R.layout.layitem, arg2, false); 
     tv = (TextView) v.findViewById(R.id.textView1); 
     tv.setLayoutParams(new LinearLayout.LayoutParams(width, width/2)); 
     // tv.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL); 

    } 

    else 
    { 
     v = arg1; 
     tv = (TextView) v.findViewById(R.id.textView1); 

    } 

    if(arg0 < count) 
    { 
     Bitmap object = getImage(iurl[arg0]); 
     tv.setBackground(new BitmapDrawable(conn.getResources(), object)); 
     tv.setText(texts[arg0]); 
    } 

    else 
    { 
     tv.setBackgroundResource(R.drawable.wish); 
     tv.setText(""); 

    } 

    return v; 
} 

我想要做的是我的ListView有20行,我的記錄數少於20.so記錄填滿了行,其餘的都有默認背景image.count是實際的記錄數。

iurl是包含要從服務器獲取的圖像名稱的數組,而文本是包含消息的數組。

問題是,arg0不超過2,所有行包含索引從0到2的圖像,當我向下滾動,它改變圖像對應的行號。

我可以在正確的行中放置正確的圖像在第一個立場,否則它只會滾動。

我設置了textview的寬度,根據mobile.is的屏幕寬度,它是正確的方式.kindly更新。

回答

0

我想你應該使用asyntask從互聯網上的特定網址獲取圖像。 如果你不使用線程從互聯網加載圖像,加載圖像和崩潰程序將需要很長時間

+0

沒有圖像加載的問題。顯然,我正在通過asynctask做.images加載正常。 – user2779311

0

你重寫了getCount()方法嗎?它應該返回由該適配器表示的數據集中的項目數量。

+0

是的,它返回20,因爲listview顯示20條記錄,但問題出現在它顯示的圖像中。當我向下滾動 – user2779311

+0

只是爲了澄清,那麼文本呢?一樣的問題? – need1milliondollars

+0

沒有他們正確顯示。他們加載得太快,他們的過渡是不可見的。 – user2779311