Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Loading data like facebook and twitter

Tags:

android

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?

like image 973
carora3 Avatar asked May 06 '26 13:05

carora3


1 Answers

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;
    }
}
}
like image 151
Andro Selva Avatar answered May 09 '26 02:05

Andro Selva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!