2016-08-15 5 views
1

私はrecyclerviewに関する非常に限られた知識でアンドロイドに飛び乗ったばかりです。私は、AAビットを使用しますが、me.CheckでonBindViewHolder.Pleaseクマの内側に以下のコードをテキストの設定状況に直面している:RecyclerViewの設定テキスト

この資料の内容をここでは、JSONです:

[ 
    { 
    "restaurantSubscriptionType_Id": 1, 
    "noOfDaysPlan": "1 Day Trial Meal", 
    "restaurantSubscriptionEntity": [ 
     { 
     "restaurantSubscriptionId": 39, 
     "subscriptionPlan": "Breakfast & Lunch", 
     "subscriptionImagePath": null, 
     "subscriptionDays": 1, 
     "subscriptionAmount": 150, 
     "restaurant_Subscription_Type_Id": 1 
     } 
    ], 
    "restaurantId": 224 
    }, 
    { 
    "restaurantSubscriptionType_Id": 2, 
    "noOfDaysPlan": "5 Days Weekly Plan", 
    "restaurantSubscriptionEntity": [ 
     { 
     "restaurantSubscriptionId": 40, 
     "subscriptionPlan": "Breakfast & Lunch", 
     "subscriptionImagePath": null, 
     "subscriptionDays": 5, 
     "subscriptionAmount": 650, 
     "restaurant_Subscription_Type_Id": 2 
     }, 
     { 
     "restaurantSubscriptionId": 41, 
     "subscriptionPlan": "Only Lunch", 
     "subscriptionImagePath": null, 
     "subscriptionDays": 5, 
     "subscriptionAmount": 500, 
     "restaurant_Subscription_Type_Id": 2 
     } 
    ], 
    "restaurantId": 224 
    } 
] 

私はpojo2schemaを持っていますサイト

2.RestaurantSubscriptionEntity

public class RestaurantSubscriptionEntity { 
private Integer restaurantSubscriptionId; 
private String subscriptionPlan; 
private String subscriptionImagePath; 
private Integer subscriptionDays; 
private Long subscriptionAmount; 
private Integer restaurantSubscriptionTypeId; 

public RestaurantSubscriptionEntity(){ 

} 

public Integer getRestaurantSubscriptionId() { 
    return restaurantSubscriptionId; 
} 

public void setRestaurantSubscriptionId(Integer restaurantSubscriptionId) { 
    this.restaurantSubscriptionId = restaurantSubscriptionId; 
} 

public String getSubscriptionPlan() { 
    return subscriptionPlan; 
} 

public void setSubscriptionPlan(String subscriptionPlan) { 
    this.subscriptionPlan = subscriptionPlan; 
} 

public String getSubscriptionImagePath() { 
    return subscriptionImagePath; 
} 

public void setSubscriptionImagePath(String subscriptionImagePath) { 
    this.subscriptionImagePath = subscriptionImagePath; 
} 

public Integer getSubscriptionDays() { 
    return subscriptionDays; 
} 

public void setSubscriptionDays(Integer subscriptionDays) { 
    this.subscriptionDays = subscriptionDays; 
} 

public Long getSubscriptionAmount() { 
    return subscriptionAmount; 
} 

public void setSubscriptionAmount(Long subscriptionAmount) { 
    this.subscriptionAmount = subscriptionAmount; 
} 

public Integer getRestaurantSubscriptionTypeId() { 
    return restaurantSubscriptionTypeId; 
} 

public void setRestaurantSubscriptionTypeId(Integer restaurantSubscriptionTypeId) { 
    this.restaurantSubscriptionTypeId = restaurantSubscriptionTypeId; 
} 

3.DemoItemAll:

01 /私は

holder.price_tv.setTextそれにアクセスしますRecyclerView

public class DemoAdapter extends RecyclerView.Adapter<DemoAdapter.MyViewHolder> { 

    private List<DemoItemAll> demoItemAllArrayList = new ArrayList<>(); 

    ImageLoader imageLoader = AppController.getInstance().getImageLoader(); 

    public static class MyViewHolder extends RecyclerView.ViewHolder { 
     private TextView title_tv,price_tv; 
     private Button drop_down_button; 

     public MyViewHolder(View itemView) { 
      super(itemView); 

      title_tv = (TextView) itemView.findViewById(R.id.day_plan_demo_tv_id); 
      price_tv = (TextView) itemView.findViewById(R.id.price_demo_tv_id); 
      drop_down_button = (Button) itemView.findViewById(R.id.demo_drop_down_btn_id); 



     } 
    } 


    public DemoAdapter(List<DemoItemAll> demoItemAllArrayList) { 
     this.demoItemAllArrayList = demoItemAllArrayList; 

    } 

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

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

     DemoItemAll demoItemAll=new DemoItemAll(); 

     //noOfDays 
     holder.title_tv.setText(demoItemAll.getNoOfDaysPlan()); 

    } 


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

    } 
} 

を拡張

4.Here私のクラスは今ここにonBindView内部、私はこれを設定する必要がありますが、 "subscriptionAmount" はRestaurantSubscriptionEntity class.Howに属し/ subscriptionAmount。

+1

DemoItemAll demoItemAll = demoItemAllArrayList.get(position);

を使用する必要が

は* * 'RecyclerView'の問題ではありません。これは設計上の問題です。あなたの 'Adapter'に' DemoItemAll'のdemoItemAllArrayListがあり、 'RestaurantSubscriptionEntity'のリストが含まれています。問題は、 'DemoItemAll'、' RestaurantSubscriptionEntity'、またはその両方のリストが必要なのかどうかです。説明してください!また、あなたの質問を再読し、できるだけ簡潔かつ一般的にしてみてください。 – Abbas

+0

はい私はそのフィールドにアクセスしたいと思うRestaurantSubscriptionEntityのリストをしたいです – notTdar

+0

あなたのアダプタに 'List demoItemAllArrayList'があるのはなぜですか?アダプタに 'RestaurantSubscriptionEntity'アイテムの実際のリストを渡すだけではどうでしょうか。 – Abbas

答えて

0
@Override 
public void onBindViewHolder(MyViewHolder holder, int position) { 

    DemoItemAll demoItemAll = demoItemAllArrayList.get(position); 
    List<RestaurantSubscriptionEntity> entity = demoItemAll.getRestaurantSubscriptionEntity(); 

    holder.title_tv.setText(demoItemAll.getNoOfDaysPlan()); 
    holder.price_tv.setText(String.valueOf(entity.getSubscriptionAmount())) 
} 
0

新しい空のDemoItemAllオブジェクトを作成するだけです。あなたはこのすべての最初の代わりに

DemoItemAll demoItemAll = new DemoItemAll();

関連する問題