使用是布局
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<android.support.v4.widget.SwipeRefreshLayout android:id="@id/id_swiperefreshlayout" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.v7.widget.RecyclerView android:id="@id/id_recyclerview" android:layout_width="match_parent" android:layout_height="match_parent" android:cacheColorHint="@null" android:scrollbars="vertical" /> </android.support.v4.widget.SwipeRefreshLayout>
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerview.setLayoutManager(layoutManager);
adapter = new BroadcastRecyclerViewAdapter(context, list,userModel);
mRecyclerview.setAdapter(adapter);
mSwipeRefreshWidget.setColorSchemeColors(R.color.btn_blue_normal,R.color.btn_blue_pressed);
mSwipeRefreshWidget.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
mType=1;page=1;
initData();
}
});
RecyclerView.Adapteret用户
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
public class BroadcastRecyclerViewAdapter extends RecyclerView.Adapter<BroadcastViewHolder> { public LayoutInflater mLayoutInflater; List<BroadcastDetailsModel> mDatas; private Context mContext; UserDetails userModel; BroadcastAPI broadcastApi; private IOnItemClickListener<BroadcastDetailsModel> onItemClickListener; public BroadcastRecyclerViewAdapter(Context context, List<BroadcastDetailsModel> datas,UserDetails userModel){ mLayoutInflater=LayoutInflater.from(context); this.mDatas=datas; mContext=context; this.userModel=userModel; broadcastApi=new BroadcastAPI(); } // 点击事件接口 public interface OnItemClickListener { void onItemClick(View view, int position,BroadcastDetailsModel model); void onItemLongClick(View view, int position,BroadcastDetailsModel model); } public OnItemClickListener mOnItemClickListener; public void setOnItemClickListener(OnItemClickListener listener) { this.mOnItemClickListener = listener; } public void addItemLast(List<BroadcastDetailsModel> datas) { mDatas.addAll(datas); } public void addItemTop(List<BroadcastDetailsModel> datas) { mDatas = datas; } @Override public int getItemCount() { return mDatas==null?0:mDatas.size(); } @Override public void onBindViewHolder(final BroadcastViewHolder holder, final int position) { final BroadcastDetailsModel model=mDatas.get(position); int type = getItemViewType(position); //点击事件在这里实现,主要是利用RecyclerView中填充的布局控件可以被点击这个原理 if (mOnItemClickListener != null) { holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mOnItemClickListener.onItemClick(holder.itemView, position,model); } }); // 长点击事件 holder.itemView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { mOnItemClickListener.onItemLongClick(holder.itemView, position,model); return true; } }); } holder.text_loaction.setVisibility(View.VISIBLE); holder.text_loaction.setText(model.getProvince() + ","+ model.getCity()); } @Override public BroadcastViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View mView=null; BroadcastViewHolder mViewHolder=null; mView = mLayoutInflater.inflate(R.layout.broadcast_fragment_item, parent, false); mViewHolder = new BroadcastViewHolder(mView); return mViewHolder; } public class BroadcastViewHolder extends RecyclerView.ViewHolder { @Bind(R.id.img_icon) public RoundImageView img_icon; @Bind(R.id.text_loaction) public CustomTextView text_loaction; public BroadcastViewHolder(View view) { super(view); ButterKnife.bind(this, view); } }
这里只实现了刷新还没有实现上拉加载更多,这里主要是记录下引用android-support-v7-recyclerview.jar 遇到的问题,刚开始我引用 了sdk\extras\android\support\v7\recyclerview\libs下的jar包
运行后提示我找这个类 在网上找了很多有说v4和v7包不一至,我换了sdk\extras\android\support文件夹下的 v4和v7依然没能解决,网上有人说用
sdk\extras\android\m2repository\com\android\support\recyclerview-v7\[版本号] 选择版本号 打开后找到recyclerview-v7-21.0.0.aar 然后解压 找到class.jar然后我将名字改为android-support-v7-recyclerview.jar
我试了 21 ,22,22.2,23.0版本都不行,我的开发环境是eclipse sdk 5.1.1
最后没办法我将sdk\extras\android\support\v7\recyclerview 项目导入到eclipse工程中 然后设置成类库 然后项目引用这个类型 在次运行 就没问题了
不知道是什么原因或者说自带的jar包是不是少什么东西,一直没解决如果有解决的或是什么原因引用的还望告知^0^