Android:载入像Facebook和Twitter这样的数据 [英] Android: Loading data like facebook and twitter

查看:128
本文介绍了Android:载入像Facebook和Twitter这样的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道如何为Twitter和Facebook应用程序加载数据.

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

就像到达页面末尾一样,您仍在与UI交互,并显示正在加载更多数据.

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.

更清楚地说,当您向下滚动新闻提要时,到达某个点时,它会显示一个圆圈,描绘着正在加载其他数据,然后当有更多新的提要可用时,您也可以滚动查看.m足够清楚..我只想知道这种情况是如何实现的..有例子吗?

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?

推荐答案

以下链接可能会帮助您完成操作.

Here are few links which might get you through it.

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

Android无限列表

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

链接二中的示例逻辑,

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;
    }
}
}

这篇关于Android:载入像Facebook和Twitter这样的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆