2011-12-29 8 views
3

私は思っていたどのようにあなたはまだUIと対話しているページの最後に到達するときのように... TwitterやFacebookアプリをアンドロイド:ロードFacebookなどのデータやTwitter

をデータロードを行い、それが更なるデータを示していますこれはプログラム的にどのように行われていますか?

さらに明確にするために、ニュースフィードを下にスクロールすると、ポイントに達すると、さらにデータがロードされていることを示す円が表示され、さらに新しいフィードが利用可能になると、それをスクロールできます。私はちょうどそのようなシナリオがどのように実装されているのか知りたがっています。

+0

私はあなたがここに読み始めるお勧め: http://developer.android.com /training/index.htmlよろしくお願いします。 Giacomo – gsscoder

答えて

6

ここにはリンクがいくつかあります。

http://github.com/commonsguy/cwac-endless

Android Endless List

http://www.androidguys.com/2009/10/21/tutorial-autogrowing-listview/

リンク2からのサンプルロジック、

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; 
    } 
} 
} 
関連する問題