Android_RecyclerView&SwipeRefreshLayout_swiperefreshlayout不显示_解决
来源:互联网 发布:学java软件开发好不好 编辑:程序博客网 时间:2024/05/15 08:32
@作者 : 西野奈留
@博客:http://blog.csdn.net/narunishino
-2016/5/18-
沉重的教训啊!
昨天下午搞了一个下午,然后到现在才解决…..真是郁闷…
具体情况:下拉的时候swiperefreshlayout不显示。
布局文件:<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeRefreshLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" /></android.support.v4.widget.SwipeRefreshLayout>
上面的布局代码明明没有错啊,为什么swiperefreshlayout就是不显示呢。
原因是:在MainActivity的onCreat中,我只写了以下的代码:
private void initRecycler() { RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); if (recyclerView != null) { recyclerView.setLayoutManager(new LinearLayoutManager(this)); //真是坑.... //recyclerView.setAdapter(new RecyclerAdapter(this)); } } private void init() { final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout); if (swipeRefreshLayout != null) { swipeRefreshLayout.setColorSchemeColors(Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { swipeRefreshLayout.postDelayed(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(false); } }, 5000); } }); } }
,没有加上adapter….
加了adapter就没事了….我了个去!!!!!!!
啊啊啊啊啊啊啊啊。。。。。。。。。。。。。。。。。。。。。。。。。。。
//RecyclerAdapter.javapublic class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyHolder> { private Context mContext; private List<String> mData; public RecyclerAdapter(Context context) { mContext = context; mData = new ArrayList<>(); for (int i = 0; i < 5; i++) { mData.add(i + "行"); } } @Override public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) { MyHolder holder = new MyHolder(LayoutInflater.from(mContext).inflate(R.layout.tv_item, parent, false)); return holder; } @Override public void onBindViewHolder(MyHolder holder, int position) { holder.tv.setText(mData.get(position)); } @Override public int getItemCount() { return mData.size(); } class MyHolder extends RecyclerView.ViewHolder { TextView tv; public MyHolder(View itemView) { super(itemView); tv = (TextView) itemView.findViewById(R.id.tvItem); } }}
//tv_item.xml<?xml version="1.0" encoding="utf-8"?><TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tvItem" android:layout_width="match_parent" android:layout_height="50dp"></TextView>
-End-
0 0
- Android_RecyclerView&SwipeRefreshLayout_swiperefreshlayout不显示_解决
- Android_RecyclerView
- Android_RecyclerView
- Android_RecyclerView
- Android_RecyclerView(1)
- 帮忙解决,图片不显示
- 解决logcat不显示log
- 解决Graphical Layout不显示
- 解决TortoiseGit图标不显示
- jenkis解决报告不显示
- 解决:menu/ActionBar不显示
- 母版页_网页中不显示
- 解决Xcode9 app 图标不显示 iOS11app图标不显示
- 解决combox重设emptyText不显示
- 网页不显示flash动画的解决
- 解决cairo-dock不显示问题
- 三星移动硬盘不显示的解决
- 解决诺顿不显示盾牌图标方法
- java学习 Controller小记
- 设计模式总结
- awk print与printf的差别
- url特殊字符转义及解决方法(附有例子)
- this android sdk requires ADT version 23
- Android_RecyclerView&SwipeRefreshLayout_swiperefreshlayout不显示_解决
- java 多线程 总结 案例
- 45-50K技术经理只为技能需求
- AFNetWorking实现GET、POST
- 不能将参数 1 从“const char [5]”转换为“LPCTSTR”
- NoClassDefFoundError: org/apache/ibatis/session/SqlSession
- 文件流
- studio提示非法字符:'\ufeff'
- 11g RAC 环境配置GRID时检查ASM报PRVG-10122