Android Recycleview Recycleview:未连接适配器;跳过布局

Android Recycleview Recycleview:未连接适配器;跳过布局,android,android-recyclerview,Android,Android Recyclerview,我有一个回收演示,但当我运行演示时,总是显示错误消息“Recycleview Recycleview:未连接适配器;跳过布局” 这是我的主要活动课 public class MainActivity extends BaseActivity{ // private ListView mListView; private ArrayList<Note> noteList; private RecycleViewNoteListAdatper noteListAdapter; pri

我有一个回收演示,但当我运行演示时,总是显示错误消息“Recycleview Recycleview:未连接适配器;跳过布局”

这是我的主要活动课

public class MainActivity extends BaseActivity{

//  private ListView mListView;
private ArrayList<Note> noteList;
private RecycleViewNoteListAdatper noteListAdapter;
private SwipeRefreshLayout mSwipeRefreshLayout;
private DrawerLayout drawerLayout;
private View drawerView;
private Toolbar mToolbar;
private RecyclerView mRecycleView;

@SuppressLint("NewApi") @Override
protected void onCreate(Bundle savedInstanceState) {
//      requestWindowFeature(Window.);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initView();
    initData();
    initListener();
//      colorChange();
    if (android.os.Build.VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        // 很明显,这两货是新API才有的。
//          window.setStatusBarColor(colorBurn(R.color.colorPrimary));
//          window.setNavigationBarColor(colorBurn(R.color.colorPrimary));
    }

}

@SuppressLint("NewApi") 
private void initView() {
    mRecycleView = (RecyclerView) findViewById(R.id.recycler_view);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitle("全部内容");
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    mToolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
    setSupportActionBar(mToolbar);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(
            this, drawerLayout, mToolbar, R.string.open_string,
            R.string.close_string);
    actionBarDrawerToggle.syncState();
    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
    mSwipeRefreshLayout.setColorSchemeColors(R.color.colorPrimary);
    mSwipeRefreshLayout.setEnabled(true);
    mSwipeRefreshLayout
            .setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    // 执行刷新操作
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            mSwipeRefreshLayout.setRefreshing(false);
                        }
                    }, 3000);
                }
            });

      FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);



//          fab.attachToListView(mRecycleView, );
    ScrollDirectionListener listener=  new ScrollDirectionListener() {
          @Override
          public void onScrollDown() {
              LogUtils.d("ListViewFragment", "onScrollDown()");
          }

          @Override
          public void onScrollUp() {
              LogUtils.d("ListViewFragment", "onScrollUp()");
          }
      };/*, new AbsListView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(AbsListView view, int scrollState) {
              LogUtils.d("ListViewFragment", "onScrollStateChanged()");
          }

          @Override
          public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
              LogUtils.d("ListViewFragment", "onScroll()");
          }
      }*/
    fab.attachToRecyclerView(mRecycleView, listener);
}

private void initData() {
    noteList = new ArrayList<Note>();
    Note note = null;
    for (int i = 0; i < 50; i++) {
        note = new Note();
        String md5Encode = MD5Utils.MD5Encode(String.valueOf(System
                .currentTimeMillis()) + i + "note");
        note.setNoteName(md5Encode);
        note.setNoteMd5(md5Encode);
        noteList.add(note);
    }
//      noteListAdapter = new NoteListAdatper(this, noteList);

    //设置 RecycleView的显示方式
    LinearLayoutManager llm= new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
    mRecycleView.setLayoutManager(llm);
    RecycleViewNoteListAdatper noteAdapter=new RecycleViewNoteListAdatper(this, noteList);
    mRecycleView.setAdapter(noteListAdapter);

}

private void initListener() {
    drawerLayout.requestDisallowInterceptTouchEvent(true);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);

}

}
public类MainActivity扩展了BaseActivity{
//私有列表视图;
私有ArrayList注释列表;
私有回收设备noteListAdapter noteListAdapter;
私人SwipeRefreshLayout mSwipeRefreshLayout;
私人抽屉布局;
私人视图抽屉视图;
私有工具栏mToolbar;
私人回收视图mRecycleView;
@SuppressLint(“NewApi”)@覆盖
创建时受保护的void(Bundle savedInstanceState){
//请求窗口功能(窗口);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initData();
initListener();
//变色();
如果(android.os.Build.VERSION.SDK_INT>=21){
Window=getWindow();
// 很明显,这两货是新美国石油学会才有的。
//setStatusBarColor(colorBurn(R.color.colorPrimary));
//setNavigationBarColor(colorBurn(R.color.colorPrimary));
}
}
@SuppressLint(“新API”)
私有void initView(){
mRecycleView=(RecyclerView)findViewById(R.id.recycler\u视图);
mToolbar=(工具栏)findviewbyd(R.id.Toolbar);
mToolbar.setTitle(“全部内容");
抽屉布局=(抽屉布局)findViewById(R.id.抽屉);
mToolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
设置支持操作栏(mToolbar);
ActionBarDrawerToggle ActionBarDrawerToggle=新建ActionBarDrawerToggle(
这个,抽屉布局,mToolbar,R.string.open\u string,
R.string.close_string);
actionBarDrawerToggle.syncState();
抽屉布局。setDrawerListener(actionBarDrawerToggle);
mSwipeRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.SwipeRefreshLayout);
mSwipeRefreshLayout.setColorSchemeColors(R.color.colorPrimary);
mSwipeRefreshLayout.setEnabled(true);
MSW刷新布局
.setOnRefreshListener(新的SwipeRefreshLayout.OnRefreshListener(){
@凌驾
公共void onRefresh(){
// 执行刷新操作
new Handler().postDelayed(new Runnable()){
@凌驾
公开募捐{
mSwipeRefreshLayout.setRefresh(false);
}
}, 3000);
}
});
FloatingActionButton fab=(FloatingActionButton)findViewById(R.id.fab);
//附件组件视图(mRecycleView,);
ScrollDirectionListener=新建ScrollDirectionListener(){
@凌驾
public void onScrollDown(){
LogUtils.d(“ListViewFragment”、“onScrollDown()”);
}
@凌驾
公共无效onScrollUp(){
LogUtils.d(“ListViewFragment”、“onScrollUp()”);
}
};/*,新的AbsListView.OnScrollListener(){
@凌驾
公共无效onScrollStateChanged(AbsListView视图,int scrollState){
LogUtils.d(“ListViewFragment”,“onScrollStateChanged()”;
}
@凌驾
public void onScroll(AbsListView视图、int firstVisibleItem、int visibleItemCount、int totalItemCount){
LogUtils.d(“ListViewFragment”、“onScroll()”);
}
}*/
附加到循环视图(mRecycleView,侦听器);
}
私有void initData(){
noteList=新的ArrayList();
注=空;
对于(int i=0;i<50;i++){
注释=新注释();
String md5Encode=MD5Utils.md5Encode(String.valueOf(系统
.currentTimeMillis())+i+“注释”);
注:setNoteName(md5Encode);
注:setNoteMd5(md5Encode);
注释列表。添加(注释);
}
//noteListAdapter=新的NoteListAdatper(这个,noteList);
//设置 回收回顾的显示方式
LinearLayoutManager llm=新的LinearLayoutManager(这是LinearLayoutManager.VERTICAL,false);
mRecycleView.setLayoutManager(llm);
RecycleViewNoteListAdatper noteAdapter=新的RecycleViewNoteListAdatper(此,注释列表);
mRecycleView.setAdapter(noteListAdapter);
}
私有void initListener(){
抽屉布局。请求不允许WinterCeptTouchEvent(true);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
getMenuInflater().充气(R.menu.main,menu);
返回super.onCreateOptions菜单(菜单);
}
}
这是我的RecycleServiceAdapter代码

public class RecycleViewNoteListAdatper extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    Context mContext;
    private LayoutInflater layoutInflater;
    private ArrayList<Note> list;
    public RecycleViewNoteListAdatper(Context context,ArrayList<Note> note) {
        this.mContext=context;
        this.list=note;
        layoutInflater = LayoutInflater.from(context);  
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup paramViewGroup, int paramInt) {
        return new RecyclerViewHolder(layoutInflater.inflate(R.layout.item_notelist_2, paramViewGroup),this,mContext) ;
    }

    @Override
    public void onBindViewHolder(ViewHolder paramVH, int paramInt) {
        if(!ListUtils.isEmpty(list)){
            Note note = list.get(paramInt);
            ((RecyclerViewHolder)paramVH).tv_introduce.setText(note.getNoteName());
        }
    }

    @Override
    public int getItemCount() {
        if(!ListUtils.isEmpty(list)){
            return list.size();
        }
        return 0;
    }
    public static class RecyclerViewHolder extends RecyclerView.ViewHolder implements OnClickListener{
        RecyclerView.Adapter<ViewHolder> mAdapter;
        Context mContext;
        RelativeLayout ll_container;
        LinearLayout ll_action;
        Button action1,action2,action3;
        TextView tv_introduce;
        public RecyclerViewHolder(View view,RecyclerView.Adapter<ViewHolder> adapter,Context context) {
            super(view);
            this.mAdapter=adapter;
            this.mContext=context;
            tv_introduce = (TextView) view.findViewById(R.id.item_introduce);
            action1=(Button) view.findViewById(R.id.button1);
            action2=(Button) view.findViewById(R.id.button2);
            action3=(Button) view.findViewById(R.id.button3);
            ll_container=(RelativeLayout) view.findViewById(R.id.ll_container);
            ll_action=(LinearLayout) view.findViewById(R.id.ll_action);


            action1.setOnClickListener(this);
            action2.setOnClickListener(this);
            action3.setOnClickListener(this);

            ll_container.setOnClickListener(this);

        }
        @Override
        public void onClick(View v) {

            switch (v.getId()) {
            case R.id.button1:
                ToastUtils.showToast(mContext, "onClick1");
                break;
            case R.id.button2:
                ToastUtils.showToast(mContext, "onClick2");
                break;
            case R.id.button3:
                ToastUtils.showToast(mContext, "onClick3");
                break;
            case R.id.ll_container:
                Intent intent=new Intent(mContext,SimpleNoteEditActivity.class);
                mContext.startActivity(intent);
                break;
            default:
                break;
            }

        }       


    }
}
公共类RecycleViewNoteListAdatper扩展了RecycleView.Adapter{
语境;
私人停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场;
私有数组列表;
公共RecycleViewNoteListAdatper(上下文,数组列表注释){
this.mContext=上下文;
这个列表=注释;
layoutInflater=layoutInflater.from(上下文);
}
@凌驾
public ViewHolder onCreateViewHolder(ViewGroup paramViewGroup,int paramInt){
返回新的RecycleServiceWholder(LayoutFlater.inflate(R.layout.item_notelist_2,paramViewGroup),此,mContext);
}
@凌驾
BindViewHolder上的公共无效(ViewHolder paramVH,int paramInt){
如果(!ListUtils.isEmpty(list)){
Note=list.get(参数);
((RecycleServiceWholder)paramVH).tv_-introduct.setText(note.getNoteName());
}
}
@凌驾
public int getItemCount(){
如果(!ListUtils.isEmpty(list)){
返回list.size();
}
返回0;
}
公共静态类RecycleServiceWholder扩展了RecycleView.ViewHolder实现OnClickListener{
RecyclerView.适配器制造商;
语境;
相对的容器;
线性布局所有行动;
按钮操作1、操作2、操作3;
TextView电视节目介绍;
公共RecycleView文件夹(视图、RecycleView.Adapter适配器、上下文){
超级(视图);
这个
mRecycleView.setAdapter(noteListAdapter);
 mRecycleView.setAdapter(noteAdapter);
LinearLayoutManager llm= new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
mRecycleView.setLayoutManager(llm);
RecycleViewNoteListAdatper noteAdapter=new RecycleViewNoteListAdatper(this, noteList);
mRecycleView.setAdapter(noteAdapter);