Giter VIP home page Giter VIP logo

xcpulltoloadmorelistview's Introduction

XCPullToLoadMoreListView

This is a custom pull-down-to-load-more listview layout project,which is such as QQ chat or wechat chat listview。

XCPullToLoadMoreListView-下拉加载更多ListView控件(仿QQ、微信聊天对话列表控件)

效果图:

image image

使用方法示例:

public class MainActivity extends AppCompatActivity {

ListView mListView;
MyAdapter mAdapter;
XCPullToLoadMoreListView mPTLListView;
List<String> mList = new ArrayList<>(0);
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    init();

}

private void init() {
    for(int i = 191;i <=200; i ++){
        mList.add("Item "+ i);
    }
    mPTLListView = (XCPullToLoadMoreListView) findViewById(R.id.list);

    mPTLListView.setOnRefreshListener(new XCPullToLoadMoreListView.OnRefreshListener() {

        @Override
        public void onPullDownLoadMore() {
            Log.v("czm", "onRefreshing");
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {

                    List<String> list = new ArrayList<String>();
                    int i = 200 - mList.size() - 10 + 1;
                    int count = 0;
                    while (count < 10) {
                        list.add("Item " + i);
                        i++;
                        count++;
                    }
                    mList.addAll(0, list);
                    mAdapter.notifyDataSetChanged();
                    mPTLListView.onRefreshComplete();
                }
            }, 1000);
        }
    });

    mListView = mPTLListView.getListView();
    mAdapter = new MyAdapter();
    mListView.setAdapter(mAdapter);
}
private class MyAdapter extends BaseAdapter {
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = new TextView(getApplicationContext());
            convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
                    , DensityUtil.dip2px(getApplicationContext(), 80)));
            holder.text = (TextView) convertView;
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.text.setText(mList.get(position));
        holder.text.setTextColor(Color.BLACK);
        holder.text.setGravity(Gravity.CENTER_VERTICAL);

// holder.text.setBackgroundColor(Color.WHITE); return convertView; }

    class ViewHolder{
        TextView text;
    }
}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.