SORU
11 NİSAN 2010, Pazar


özel adaptörü getView yöntemi, birden çok kez, ve tutarlı bir sırayla çağrıldığını liste görünümü

Özel liste adaptör var:

class ResultsListAdapter extends ArrayAdapter<RecordItem> {

geçersiz kılınmış 'getView' yöntemi nedir ve convertView olup olmadığını kontrol etmek için bir yazdırma:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        System.out.println("getView "   position   " "   convertView);

Bu listedeki ilk giriş henüz hiçbir kullanıcı görüntülendiğinde () çıktısı

04-11 16:24:05.860: INFO/System.out(681): getView 0 null  
04-11 16:24:29.020: INFO/System.out(681): getView 1 android.widget.RelativeLayout@43d415d8  
04-11 16:25:48.070: INFO/System.out(681): getView 2 android.widget.RelativeLayout@43d415d8  
04-11 16:25:49.110: INFO/System.out(681): getView 3 android.widget.RelativeLayout@43d415d8  
04-11 16:25:49.710: INFO/System.out(681): getView 0 android.widget.RelativeLayout@43d415d8  
04-11 16:25:50.251: INFO/System.out(681): getView 1 null  
04-11 16:26:01.300: INFO/System.out(681): getView 2 null  
04-11 16:26:02.020: INFO/System.out(681): getView 3 null  
04-11 16:28:28.091: INFO/System.out(681): getView 0 null  
04-11 16:37:46.180: INFO/System.out(681): getView 1 android.widget.RelativeLayout@43cff8f0  
04-11 16:37:47.091: INFO/System.out(681): getView 2 android.widget.RelativeLayout@43cff8f0  
04-11 16:37:47.730: INFO/System.out(681): getView 3 android.widget.RelativeLayout@43cff8f0  

Açıkça ifade bulamadım ama bildiğim kadarıyla, () getView sadece görünen satırlar için denir. Benim app dört görünür satır ile başlar beri en az pozisyon numaraları 0-3 gelen bisiklet mantıklı. Ama gerisi okunmuyor

  • Neden her satır için üç kere aradı getview?
  • Nerede bu convertViews henüz kaydırılan almadım ne zaman geliyor?

Biraz araştırma yaptım ve iyi bir cevap almadan, insanların düzen sorunları ile bu sorunu ilişkilendirme olduğunu fark ettim. Bu yüzden, burada listesini içeren düzen

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

    <TextView android:id="@ id/pageDetails"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" />

    <ListView android:id="@ id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:drawSelectorOnTop="false" />

</LinearLayout>

ve her bir satır düzeni:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="108dp"    
android:padding="4dp">

<ImageView
    android:id="@ id/thumb"        
    android:layout_width="120dp"
    android:layout_height="fill_parent"        
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginRight="8dp"        
    android:src="@drawable/loading" />

<TextView  
    android:id="@ id/price"
    android:layout_width="wrap_content"
    android:layout_height="18dp"         
    android:layout_toRightOf="@id/thumb"
    android:layout_alignParentBottom="true"       
    android:singleLine="true" />

<TextView  
    android:id="@ id/date"
    android:layout_width="wrap_content"
    android:layout_height="18dp"         
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true" 
    android:paddingRight="4dp"       
    android:singleLine="true" />

<TextView
    android:id="@ id/title"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="17dp" 
    android:layout_toRightOf="@id/thumb"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:paddingRight="4dp"   
    android:layout_alignWithParentIfMissing="true"
    android:gravity="center" />

</RelativeLayout>

Zaman ayırdığınız için teşekkür ederim

CEVAP
14 NİSAN 2010, ÇARŞAMBA


Bu bir sorun değildir, tamamen sipariş üzerine getView() adı verilecek ne de kaç kere garanti yok. Belirli bir durumda height=wrap_content bir vererek en kötü şey ListView ile mümkün yapıyorsun. Bu ListView düzeni zamanda adaptörün bir kaç çocuk, nasıl olması gerektiğini bilmek ölçmek için zorlar. Bu kaydırma bile önce getView() geçti gördün convertViews ListView sağlar.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • boogie2988

    boogie2988

    6 NİSAN 2006
  • Brendan van Son

    Brendan van

    5 Aralık 2006
  • DroidModderX ROOT Master

    DroidModderX

    14 ŞUBAT 2011