|  |  | 
 |  |  | package com.example.agvcontroller; | 
 |  |  |  | 
 |  |  | import static androidx.core.content.ContextCompat.startActivity; | 
 |  |  |  | 
 |  |  | import android.content.Intent; | 
 |  |  | import android.view.LayoutInflater; | 
 |  |  | import android.view.View; | 
 |  |  | import android.view.ViewGroup; | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public int getItemViewType(int position) { | 
 |  |  |         return R.layout.item_view_linear; | 
 |  |  |         //if (itemList == null || itemList.isEmpty()) { | 
 |  |  |         //    return R.layout.item_layout; | 
 |  |  |         //} else { | 
 |  |  |         //    return R.layout.item_view_linear; | 
 |  |  |         //} | 
 |  |  |         //return R.layout.item_view_linear; | 
 |  |  |         if (itemList == null || itemList.isEmpty()) { | 
 |  |  |             return R.layout.item_layout; | 
 |  |  |         } else { | 
 |  |  |             return R.layout.item_view_linear; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |     @NonNull | 
 |  |  |     @Override | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void onBindViewHolder(@NonNull ViewHolder holder, int position) { | 
 |  |  |         Item item = itemList.get(position); | 
 |  |  |         holder.ip.setText("设备IP: " + item.getIp()); | 
 |  |  |         holder.title.setText("设备编号: " + item.getText()); | 
 |  |  |         //if (itemList == null || itemList.isEmpty()) { | 
 |  |  |         //    // 默认显示页面 | 
 |  |  |         //    //return 1; | 
 |  |  |         //} else { | 
 |  |  |         //    // 数据显示页面 | 
 |  |  |         //    Item item = itemList.get(position); | 
 |  |  |         //    holder.ip.setText("设备IP: " + item.getIp()); | 
 |  |  |         //    holder.title.setText("设备编号: " + item.getText()); | 
 |  |  |         //} | 
 |  |  |         //Item item = itemList.get(position); | 
 |  |  |         //holder.ip.setText("设备IP: " + item.getIp()); | 
 |  |  |         //holder.title.setText("设备编号: " + item.getText()); | 
 |  |  |         if (itemList == null || itemList.isEmpty()) { | 
 |  |  |             // 默认显示页面 | 
 |  |  |             //return 1; | 
 |  |  |         } else { | 
 |  |  |             // 数据显示页面 | 
 |  |  |             Item item = itemList.get(position); | 
 |  |  |             holder.ip.setText("设备IP: " + item.getIp()); | 
 |  |  |             holder.title.setText("设备编号: " + item.getText()); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public int getItemCount() { | 
 |  |  |         return itemList.size(); | 
 |  |  |         //if (itemList == null || itemList.isEmpty()) { | 
 |  |  |         //    return 1; | 
 |  |  |         //} else { | 
 |  |  |         //    return itemList.size(); | 
 |  |  |         //} | 
 |  |  |         //return itemList.size(); | 
 |  |  |         if (itemList == null || itemList.isEmpty()) { | 
 |  |  |             return 1; | 
 |  |  |         } else { | 
 |  |  |             return itemList.size(); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void addItem (Item item) { | 
 |  |  |         itemList.add(item); | 
 |  |  |         notifyItemInserted(itemList.size() - 1); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | } |