3

I was just wondering how does data loads for Twitter and Facebook apps..

Like when you reach end of page you're still interacting with UI and it shows the further data is loading.. How is this programatically done.

To be more clear, when you scroll down your news feed when you reach a point it shows a circle depicting further data is loading and then when further new feed is available you can scroll through that as well.. I hope I'm clear enough.. I just want to know how is such scenario implemented.. Is there any example?

carora3
  • 466
  • 1
  • 5
  • 19
  • I suggest you start reading here: http://developer.android.com/training/index.html Regards, Giacomo – gsscoder Dec 29 '11 at 07:12

1 Answers1

6

Here are few links which might get you through it.

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

Android Endless List

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

A sample logic from the link two,

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;
    }
}
}
Community
  • 1
  • 1
Andro Selva
  • 53,910
  • 52
  • 193
  • 240