E / RecyclerView:没有连接适配器;跳过布局android

时间:2017-04-24 20:08:04

标签: java android android-layout android-fragments

我有一个带有4个片段的标签式活动,在第四个片段(设置片段)我想显示一个回收者视图菜单,当我运行我的项目时,回收者视图菜单非常慢并且得到了E / RecyclerView:没有适配器连接;跳过布局 ,我已经搜索了解决方案,但对我来说没什么用。

日志

E/RecyclerView: No adapter attached; skipping layout
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode 
(without mOwningView)
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 
0) or=1
E/RecyclerView: No adapter attached; skipping layout
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@5f44d70 
time:10538964
V/ActivityThread: updateVisibility : ActivityRecord{98c56e4 
token=android.os.BinderProxy@6559f5e 
{com.example.zodiac.sawa/com.example.zodiac.sawa.MainActivity}} show : false

这是我的适配器(SettingAdapter.java):

 package com.example.zodiac.sawa.RecyclerViewAdapters;

 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.SeekBar;
 import android.widget.TextView;

 import com.example.zodiac.sawa.R;
 import com.example.zodiac.sawa.models.SettingsRecyclerViewDataProvider;

 import org.w3c.dom.Text;

 import java.util.ArrayList;


 public class SettingsAdapter extends 
 RecyclerView.Adapter<SettingsAdapter.RecyclerViewHolder> {
 ArrayList<SettingsRecyclerViewDataProvider> 
 settingsRecyclerViewDataProviders = new 
 ArrayList<SettingsRecyclerViewDataProvider>();
 View view;

public SettingsAdapter(ArrayList<SettingsRecyclerViewDataProvider> settingsRecyclerViewDataProviders) {
    this.settingsRecyclerViewDataProviders = settingsRecyclerViewDataProviders;
}

@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    view = LayoutInflater.from(parent.getContext()).inflate(R.layout.settings_item_view, parent, false);
    RecyclerViewHolder recyclerViewHolder = new RecyclerViewHolder(view);
    return recyclerViewHolder;
}

@Override
public void onBindViewHolder(RecyclerViewHolder holder, int position) {
    SettingsRecyclerViewDataProvider dataProvider = settingsRecyclerViewDataProviders.get(position);
    holder.image.setImageResource(dataProvider.getImage());
    holder.text.setText(dataProvider.getText());


}

@Override
public int getItemCount() {
    return settingsRecyclerViewDataProviders.size();
}

public class RecyclerViewHolder extends RecyclerView.ViewHolder {
    ImageView image;
    ;
    TextView text;

    public RecyclerViewHolder(View view) {
        super(view);
        image = (ImageView) view.findViewById(R.id.image);
        text = (TextView) view.findViewById(R.id.text);


    }
}
}

这里是片段代码

package com.example.zodiac.sawa.MainTabs;

/ **  *由zodiac于03/27/2017创建。  * /

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zodiac.sawa.R;
import com.example.zodiac.sawa.RecyclerViewAdapters.SettingsAdapter;
import com.example.zodiac.sawa.models.SettingsRecyclerViewDataProvider;

import java.util.ArrayList;

public class Setting extends Fragment {
  View view;
  RecyclerView recyclerView;
  SettingsAdapter recyclerAdapter;
  RecyclerView.LayoutManager layoutManager;
  int image1=R.drawable.image1;
  int image2=R.drawable.image2;
  int image3=R.drawable.image1;
ArrayList<SettingsRecyclerViewDataProvider>dataProviders=newArrayList<SettingsRecyclerViewDataProvider>();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view=  inflater.inflate(R.layout.setting_tab,container,false);
    recyclerView=(RecyclerView)view.findViewById(R.id.recycler);
    SettingsRecyclerViewDataProvider settingsRecyclerViewDataProvider=new SettingsRecyclerViewDataProvider(image1,"Your name");
    dataProviders.add(settingsRecyclerViewDataProvider);
    dataProviders.add(settingsRecyclerViewDataProvider);
    dataProviders.add(settingsRecyclerViewDataProvider);

    recyclerAdapter=new SettingsAdapter(dataProviders);
    recyclerView.setHasFixedSize(true);
    layoutManager=new LinearLayoutManager(getContext());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(recyclerAdapter);

    return view;
}
}

这是我的settingsRecyclerViewDataProviders.java类

package com.example.zodiac.sawa.models;



public class SettingsRecyclerViewDataProvider {
int image;
String text;
public SettingsRecyclerViewDataProvider(int image,String text){
    this.image=image;
    this.text=text;
}

public void setImage(int image) {
    this.image = image;
}

public void setText(String text) {
    this.text = text;
}

public int getImage() {
    return image;
}

public String getText() {
    return text;
 }
}

0 个答案:

没有答案