Search in sources :

Example 1 with ChatMessage

use of com.zhy.sample.bean.ChatMessage in project baseAdapter by hongyangAndroid.

the class MultiItemRvActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recyclerview);
    mRecyclerView = (RecyclerView) findViewById(R.id.id_recyclerview);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mDatas.addAll(ChatMessage.MOCK_DATAS);
    ChatAdapterForRv adapter = new ChatAdapterForRv(this, mDatas);
    mLoadMoreWrapper = new LoadMoreWrapper(adapter);
    mLoadMoreWrapper.setLoadMoreView(LayoutInflater.from(this).inflate(R.layout.default_loading, mRecyclerView, false));
    mLoadMoreWrapper.setOnLoadMoreListener(new LoadMoreWrapper.OnLoadMoreListener() {

        @Override
        public void onLoadMoreRequested() {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    boolean coming = Math.random() > 0.5;
                    ChatMessage msg = null;
                    msg = new ChatMessage(coming ? R.drawable.renma : R.drawable.xiaohei, coming ? "人马" : "xiaohei", "where are you " + mDatas.size(), null, coming);
                    mDatas.add(msg);
                    mLoadMoreWrapper.notifyDataSetChanged();
                }
            }, 3000);
        }
    });
    adapter.setOnItemClickListener(new CommonAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
            Toast.makeText(MultiItemRvActivity.this, "Click:" + position, Toast.LENGTH_SHORT).show();
        }

        @Override
        public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
            Toast.makeText(MultiItemRvActivity.this, "LongClick:" + position, Toast.LENGTH_SHORT).show();
            return false;
        }
    });
    mRecyclerView.setAdapter(mLoadMoreWrapper);
}
Also used : LoadMoreWrapper(com.zhy.adapter.recyclerview.wrapper.LoadMoreWrapper) ChatMessage(com.zhy.sample.bean.ChatMessage) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CommonAdapter(com.zhy.adapter.recyclerview.CommonAdapter) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) ChatAdapterForRv(com.zhy.sample.adapter.rv.ChatAdapterForRv) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

Handler (android.os.Handler)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 CommonAdapter (com.zhy.adapter.recyclerview.CommonAdapter)1 LoadMoreWrapper (com.zhy.adapter.recyclerview.wrapper.LoadMoreWrapper)1 ChatAdapterForRv (com.zhy.sample.adapter.rv.ChatAdapterForRv)1 ChatMessage (com.zhy.sample.bean.ChatMessage)1