这是我RecyclerViews
页面的代码:
public class MenuActivity extends AppCompatActivity {
private RecyclerView firstRecyclerView;
JsonArrayRequest jsonArrayRequest ;
RequestQueue requestQueue;
NestedScrollView nsv;
private ArrayList<Recipes>GetDataAdapter1;
RecyclerView.Adapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
firstRecyclerView = (RecyclerView)findViewById(R.id.recycler);
//create and set layout manager for each RecyclerView
RecyclerView.LayoutManager firstLayoutManager = new LinearLayoutManager(this);
firstRecyclerView.setLayoutManager(firstLayoutManager);
firstRecyclerView.setHasFixedSize(true);
GetDataAdapter1 = new ArrayList<>();
JSON_DATA_WEB_CALL_VIEWS();
}
这是我的RecyclerView
AdapterList
来调用列表元素的inflate视图:
public RecyclerViewAdapterList(List<Recipes> getDataAdapter, Context
context){
super();
this.itemList = getDataAdapter;
this.context = context;
}
@Override
public RecyclerViewHolders onCreateViewHolder(ViewGroup parent, int viewType) {
View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.inflate_pagecountry,
parent, false);
RecyclerViewHolders rcv = new RecyclerViewHolders(layoutView);
return rcv;
}
@Override
public void onBindViewHolder(RecyclerViewHolders holder, int position) {
holder.NameCategory.setText(itemList.get(position).getTitle());
Picasso.with(context).load(itemList.get(position).getImage()).into(holder.CategoryLogo);
}
我得到但是logcat说
15:25:53.476 E / RecyclerView:没有连接适配器;跳过布局
你能帮帮我吗?答案 0 :(得分:1)
你可以试试这个
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
nsv = (NestedScrollView) findViewById(R.id.activity_main);
firstRecyclerView = (RecyclerView)findViewById(R.id.recycler);
secondRecyclerView = (RecyclerView)findViewById(R.id.recycler_2);
thirdRecyclerView = (RecyclerView) findViewById(R.id.recycler_3);
fourthRecyclerView = (RecyclerView) findViewById(R.id.recycler_s);
fifhtRecyclerView = (RecyclerView) findViewById(R.id.recycler_);
//create and set layout manager for each RecyclerView
firstRecyclerView.setNestedScrollingEnabled(false);
RecyclerView.LayoutManager firstLayoutManager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
//RecyclerView.LayoutManager secondLayoutManager = new LinearLayoutManager(this);
//RecyclerView.LayoutManager thirdLayoutManager = new LinearLayoutManager(this);
//RecyclerView.LayoutManager fourthLayoutManager = new LinearLayoutManager(this);
//RecyclerView.LayoutManager fiveLayoutManager = new LinearLayoutManager(this);
firstRecyclerView.setLayoutManager(firstLayoutManager);
//secondRecyclerView.setLayoutManager(secondLayoutManager);
//thirdRecyclerView.setLayoutManager(thirdLayoutManager);
//fourthRecyclerView.setLayoutManager(fourthLayoutManager);
//fifhtRecyclerView.setLayoutManager(fiveLayoutManager);
firstRecyclerView.setHasFixedSize(true);
//secondRecyclerView.setHasFixedSize(true);
//thirdRecyclerView.setHasFixedSize(true);
//fourthRecyclerView.setHasFixedSize(true);
//fifhtRecyclerView.setHasFixedSize(true);
GetDataAdapter1 = new ArrayList<>();
//GetDataAdapter2 = new ArrayList<>();
//GetDataAdapter3 = new ArrayList<>();
//GetDataAdapter4 = new ArrayList<>();
//GetDataAdapter5 = new ArrayList<>();
JSON_DATA_WEB_CALL_VIEWS();
//JSON_DATA_WEB_CALL_DONES();
//JSON_DATA_WEB_CALL_LIKES();
//JSON_DATA_WEB_CALL_IDS();
//JSON_DATA_WEB_CALL_RANDOM();
}
答案 1 :(得分:0)
实际上问题是你正在初始化n个RecyclerView但只为一个分配适配器,所以你必须为所有其他RecyclerView分配适配器或注释所有其他RecyclerView