2017-12-24 3 views
1

Speaker, 헤드폰 및 MicroPhones와 같은 세 가지 제목 제목이있는 Vertical RecyclerView를 기준으로 값을 표시하고 싶습니다.이 중 세 가지가 Category.In 카테고리에는 여러 유형의 스피커 및 헤드폰과 같은이 카테고리를 기반으로 한 값이 있습니다. 문제는 가로 방향 리사이클 뷰에서 세로 머리글을 기반으로 이러한 카테고리 유형을 표시하려고한다는 것입니다. 각 카테고리에서 4 ~ 4 개의 항목을 차지하므로 가로 Recycler View에서 세로 ReclerView를 기반으로 각 항목을 표시 할 수 있습니다. 여기 어떻게 같은 값을 설정할 수 있습니까 Vertical RecyclerView 제목에서 Horizontal RecyclerView 제목으로

내가 값 여기

public class MainActivity extends AppCompatActivity implements RecyclerViewDataAdapter.OnItemClickListner { 
     private ProgressDialog progressDialog; 
     private Toolbar toolbar; 
     String category_Name, Category_ID, Product_ID, Product_Name, Product_Image, Product_Price, Product_Sale, Cart; 
     Context context; 
     ArrayList<SectionDataModel> singleItemModels; 
     ArrayList<SingleItemModel> allSampleData; 
     RecyclerView my_recycler_view, my_recycler_vieww; 


     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 
      getCategoryone(); 
      allSampleData = new ArrayList<SingleItemModel>(); 
      my_recycler_view = (RecyclerView) findViewById(R.id.my_recycler_view); 
    //  my_recycler_vieww = (RecyclerView) findViewById(R.id.recycler_view_list); 
    //  my_recycler_vieww.setHasFixedSize(true); 
    //  my_recycler_vieww.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); 

      my_recycler_view.setHasFixedSize(true); 
      my_recycler_view.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); 

     } 

     public void getCategoryone() { 

      final RequestQueue queue = Volley.newRequestQueue(getApplication()); 
      StringRequest stringRequest = new StringRequest(Request.Method.POST, "http://proaudiobrands.com/app/feature.php", 
        new Response.Listener<String>() { 
         @Override 
         public void onResponse(String response) { 
          Log.i("shabina shopping response", response); 
          try { 
           singleItemModels = new ArrayList<>(); 
           allSampleData = new ArrayList<>(); 
           JSONObject mainObj = new JSONObject(response); 
           Log.d("shabina ", response); 
           JSONArray Feature_product = mainObj.getJSONArray("Feature_product"); 

           for (int i = 0; i < Feature_product.length(); i++) { 
            SectionDataModel sectionDataModel = new SectionDataModel(); 
            JSONObject Feature_Product = Feature_product.getJSONObject(i); 
            String Category_Namee = Feature_Product.getString("Category_Namee"); 
            String Category_IDs = Feature_Product.getString("Category_IDs"); 
            JSONArray Product_List = Feature_Product.getJSONArray("Product_List"); 
            sectionDataModel.setHeaderTitle(Category_Namee); 

            for (int j = 0; j < Product_List.length(); j++) { 
             JSONObject Category_Name = Product_List.getJSONObject(j); 
             category_Name = Category_Name.getString("Category_Name"); 
             Category_ID = Category_Name.getString("Category_ID"); 
             Product_ID = Category_Name.getString("Product_ID"); 
             Product_Name = Category_Name.getString("Product_Name"); 
             Product_Image = Category_Name.getString("Product_Image"); 
             Product_Price = Category_Name.getString("Product_Price"); 
             Product_Sale = Category_Name.getString("Product_Sale"); 
             Cart = Category_Name.getString("Cart"); 
             if (j == 4) { 
              break; 

             } 

             Log.e("sushil Category_Name", category_Name + " " + Category_ID + " " + Product_ID + " " + Product_Name + " " + Product_Image + " " + Product_Price + " " + Product_Sale + " " + Cart); 
             SingleItemModel singleItemModel1 = new SingleItemModel(category_Name, Category_ID, Product_ID, Product_Name, Product_Image, Product_Price, Product_Sale, Cart); 
             allSampleData.add(singleItemModel1); 
            } 

            sectionDataModel.setAllItemsInSection(allSampleData); 
            singleItemModels.add(sectionDataModel); 
           } 


           Log.e("Single ItemModel", String.valueOf(singleItemModels)); 
           RecyclerViewDataAdapter myAdapter = new RecyclerViewDataAdapter(getApplication(), singleItemModels, MainActivity.this); 
           my_recycler_view.setAdapter(myAdapter); 
          } catch (Exception e) { 
           e.printStackTrace(); 
          } 
         } 


        }, new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        Log.e("error", error.toString()); 

       } 


      }) { 

       @Override 
       protected Map<String, String> getParams() throws AuthFailureError { 
        Map<String, String> params = new HashMap<>(); 
        params.put("method", "feature"); 
        params.put("userId", "PRO1"); 


        return params; 
       } 
      }; 
      stringRequest.setRetryPolicy(new DefaultRetryPolicy(
        90000, 
        DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 
      queue.add(stringRequest); 


     } 

     @Override 
     public void onItemClick(View view, int position) { 
      Toast.makeText(this, "Hello" + position, Toast.LENGTH_SHORT).show(); 

     } 
    } 

Here is My Vertical RecyclerView I which there is header type like HeadPhone,Speaker,MicroPhone 

public class RecyclerViewDataAdapter extends RecyclerView.Adapter<RecyclerViewDataAdapter.ItemRowHolder> { 

    private ArrayList<SectionDataModel> arrayList; 
    private Context context; 
    private OnItemClickListner onItemClickListener; 

    public interface OnItemClickListner { 
     void onItemClick(View view, int position); 
    } 

    public RecyclerViewDataAdapter(Context context, ArrayList<SectionDataModel> arrayList, OnItemClickListner onItemClickListener) { 
     this.arrayList = arrayList; 
     this.onItemClickListener = onItemClickListener; 
     this.context = context; 
    } 

    @Override 
    public ItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) { 
     View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_item, null); 
     ItemRowHolder mh = new ItemRowHolder(v); 
     return mh; 
    } 

    @Override 
    public void onBindViewHolder(ItemRowHolder holder, final int position) { 


     final String Category = arrayList.get(position).getHeaderTitle(); 
     holder.tvProduct_Name.setText(Category); 
     holder.tvProduct_Name.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Toast.makeText(context, "Postion" + arrayList.get(position).toString(), Toast.LENGTH_SHORT).show(); 
      } 
     }); 
     ArrayList<SingleItemModel> arrayListt = arrayList.get(position).getAllItemsInSection(); 

     if (arrayList.get(0).getHeaderTitle().equals(arrayListt.get(position).getCategory_Name())) { 
      SectionListDataAdapter sectionListDataAdapter = new SectionListDataAdapter(context, arrayListt); 
      holder.my_recycler_vieww.setHasFixedSize(true); 
      holder.my_recycler_vieww.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)); 
      holder.my_recycler_vieww.setAdapter(sectionListDataAdapter); 

     } 
     holder.btnMore.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Toast.makeText(context, "Hello" + arrayList.get(position), Toast.LENGTH_SHORT).show(); 
      } 
     }); 

    } 

    @Override 
    public int getItemCount() { 
     if (arrayList == null) 
      return 0; 
     return arrayList.size(); 
    } 

     public class ItemRowHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 
      private TextView tvCategory_Name, tvCategory_ID, tvProduct_ID, tvProduct_Name, tvProductPrice, tvAmount, tvSale; 
      private ImageView imgproduct; 
      RecyclerView my_recycler_vieww; 
      protected Button btnMore; 

      public ItemRowHolder(View itemView) { 
       super(itemView); 
       tvProduct_Name = (TextView) itemView.findViewById(R.id.itemTitle); 
       my_recycler_vieww = (RecyclerView) itemView.findViewById(R.id.recycler_view_list); 


       this.btnMore = (Button) itemView.findViewById(R.id.btnMore); 


      } 

      @Override 
      public void onClick(View view) { 
       onItemClickListener.onItemClick(view, getAdapterPosition()); 
      } 
     } 

    } 
Here Is Horizontal RecyclerView in which i have to display Section type 

public class SectionListDataAdapter extends RecyclerView.Adapter<SectionListDataAdapter.SingleItemRowHolder> { 

    private ArrayList<SingleItemModel> itemsList; 
    private Context mContext; 


    public interface OnItemClickListner { 
     void onItemClick(View view, int position); 
    } 

    public SectionListDataAdapter(Context context, ArrayList<SingleItemModel> itemsList) { 
     this.itemsList = itemsList; 
     this.mContext = context; 
    } 

    @Override 
    public SingleItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) { 
     View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_single_card, null); 
     SingleItemRowHolder mh = new SingleItemRowHolder(v); 
     return mh; 
    } 

    @Override 
    public void onBindViewHolder(SingleItemRowHolder holder, int i) { 
     SingleItemModel singleItem = itemsList.get(i); 

     holder.tvTitle.setText(itemsList.get(i).getCategory_Name()); 
     Picasso.with(mContext).load(singleItem.getProduct_Image()).fit().into(holder.itemImage); 


    } 

    @Override 
    public int getItemCount() { 
     return (null != itemsList ? itemsList.size() : 0); 
    } 

    public class SingleItemRowHolder extends RecyclerView.ViewHolder { 

     protected TextView tvTitle; 

     protected ImageView itemImage; 


     public SingleItemRowHolder(View view) { 
      super(view); 

      this.tvTitle = (TextView) view.findViewById(R.id.tvTitle); 
      this.itemImage = (ImageView) view.findViewById(R.id.itemImage); 


      view.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 


        Toast.makeText(v.getContext(), tvTitle.getText(), Toast.LENGTH_SHORT).show(); 

       } 
      }); 


     } 

    } 

} 

를 가져 오기하고있는 곳에서 내 주요 활동 인 것은 내 모델 클래스 다음

public class SingleItemModel { 
String Category_Name, Category_ID, Product_ID, Product_Name, Product_Image, Product_Price, Product_Sale, Cart; 

public SingleItemModel(String category_Name) { 
    Category_Name = category_Name; 
} 

public SingleItemModel(String category_Name, String category_ID, String product_ID, String product_Name, String product_Image, String product_Price, String product_Sale, String cart) { 
    Category_Name = category_Name; 
    Category_ID = category_ID; 
    Product_ID = product_ID; 
    Product_Name = product_Name; 
    Product_Image = product_Image; 
    Product_Price = product_Price; 
    Product_Sale = product_Sale; 
    Cart = cart; 
} 

public String getCategory_Name() { 
    return Category_Name; 
} 

public void setCategory_Name(String category_Name) { 
    Category_Name = category_Name; 
} 

public String getCategory_ID() { 
    return Category_ID; 
} 

public void setCategory_ID(String category_ID) { 
    Category_ID = category_ID; 
} 

public String getProduct_ID() { 
    return Product_ID; 
} 

public void setProduct_ID(String product_ID) { 
    Product_ID = product_ID; 
} 

public String getProduct_Name() { 
    return Product_Name; 
} 

public void setProduct_Name(String product_Name) { 
    Product_Name = product_Name; 
} 

public String getProduct_Image() { 
    return Product_Image; 
} 

public void setProduct_Image(String product_Image) { 
    Product_Image = product_Image; 
} 

public String getProduct_Price() { 
    return Product_Price; 
} 

public void setProduct_Price(String product_Price) { 
    Product_Price = product_Price; 
} 

public String getProduct_Sale() { 
    return Product_Sale; 
} 

public void setProduct_Sale(String product_Sale) { 
    Product_Sale = product_Sale; 
} 

public String getCart() { 
    return Cart; 
} 

public void setCart(String cart) { 
    Cart = cart; 
} 

} 

입니다 내 섹션 모델 클래스 다음

public class SectionDataModel { 

private String headerTitle; 
private ArrayList<SingleItemModel> allItemsInSection; 


public SectionDataModel() { 

} 
public SectionDataModel(String headerTitle, ArrayList<SingleItemModel> allItemsInSection) { 
    this.headerTitle = headerTitle; 
    this.allItemsInSection = allItemsInSection; 
} 



public String getHeaderTitle() { 
    return headerTitle; 
} 

public void setHeaderTitle(String headerTitle) { 
    this.headerTitle = headerTitle; 
} 

public ArrayList<SingleItemModel> getAllItemsInSection() { 
    return allItemsInSection; 
} 

public void setAllItemsInSection(ArrayList<SingleItemModel> allItemsInSection) { 
    this.allItemsInSection = allItemsInSection; 
} 

} 

입니다 내 이미지

Here is my Image

내 문제는 내 ArrayList에 12 개체 및 모든 12 개체 문 if(arrayList.get(0).getHeaderTitle().equals(arrayListt.get(position).getCategory_Name()))이 거짓 returing 및 경우 홀더 항목 my_recycler_vieww은 단순히 유형

답변

0

에 기초하여 각 어댑터에 표시하는 대신되어 있다는 것입니다 그것을 캐시 된 값으로 다시 사용하는 이유는 동일한 항목을 얻는 이유입니다. 성명은 다음과 같아야합니다.

`if(arrayList.get(0).getHeaderTitle().equals(arrayListt.get(position).getCategory_Name())) { 
       SectionListDataAdapter sectionListDataAdapter = new SectionListDataAdapter(context, arrayListt); 
       holder.my_recycler_vieww.setHasFixedSize(true); 
       holder.my_recycler_vieww.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)); 
       holder.my_recycler_vieww.setAdapter(sectionListDataAdapter); 

      } 
else{ 
    holder.my_recycler_vieww.setAdapter(null); 
}