SORU
3 Temmuz 2009, Cuma


Android Sonsuz Listesi

Nasıl daha fazla öğe yüklemek böylece haberim listenin sonuna varana kadar bir liste oluşturabilirim?

CEVAP
4 Temmuz 2009, CUMARTESİ


Bir çözüm OnScrollListener uygulamak ve değişiklikler (ürün ekleme, vb.) yapmak. onScroll çalışma yöntemi açısından uygun bir devlet ListAdapter için.

Aşağıdaki ListActivity tamsayılar listesi, kullanıcı listesi sonuna kadar kayar zaman 40, öğe ekleme ile başlangıç gösterir.

public class Test extends ListActivity implements OnScrollListener {

    Aleph0 adapter = new Aleph0();

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(adapter); 
        getListView().setOnScrollListener(this);
    }

    public void onScroll(AbsListView view,
        int firstVisible, int visibleCount, int totalCount) {

        boolean loadMore = /* maybe add a padding */
            firstVisible   visibleCount >= totalCount;

        if(loadMore) {
            adapter.count  = visibleCount; // or any other amount
            adapter.notifyDataSetChanged();
        }
    }

    public void onScrollStateChanged(AbsListView v, int s) { }    

    class Aleph0 extends BaseAdapter {
        int count = 40; /* starting amount */

        public int getCount() { return count; }
        public Object getItem(int pos) { return pos; }
        public long getItemId(int pos) { return pos; }

        public View getView(int pos, View v, ViewGroup p) {
                TextView view = new TextView(Test.this);
                view.setText("entry "   pos);
                return view;
        }
    }
}

Belli ki uzun süren eylemleri için ayrı bir iş parçacığı (web-veri yükleme gibi) kullanmanız gerekir ve ilerleme son listesinde öğe market ya da gmail apps gibi) belirtmek istiyorum.

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Ayite Atiwoto (superjiffrey)

    Ayite Atiwot

    29 EYLÜL 2010
  • Make:

    Make:

    23 Mart 2006
  • Marissah Simonini

    Marissah Sim

    25 HAZİRAN 2013