我正在尝试解析数据对象列表中的JSON数组
payment_details
。
我已经成功解析了数据数组并在可回收视图中进行了调用,但我无法调用payment_details
数组。
适配器.class
public class InProgress_Adapter extends RecyclerView.Adapter<InProgress_Adapter.InProgressViewHolder> {
private LayoutInflater inflater;
private List<Data_Inprogress> modelRecyclerArrayList;
Context ctx;
public InProgress_Adapter( Context ctx, List<Data_Inprogress> modelRecyclerArrayList) {
this.inflater = inflater.from(ctx);
this.modelRecyclerArrayList = modelRecyclerArrayList;
this.ctx = ctx;
}
@NonNull
@Override
public InProgressViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
View view = inflater.inflate(R.layout.in_progress_adapter, viewGroup, false);
InProgressViewHolder holder = new InProgressViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(@NonNull InProgressViewHolder holder, int i) {
for (i=0;i<modelRecyclerArrayList.size();i++){
holder.location1.setText(modelRecyclerArrayList.get(i).getLocaion());
holder.date1.setText(modelRecyclerArrayList.get(i).getDate());
holder.duration1.setText(modelRecyclerArrayList.get(i).getDuration());
holder.username1.setText(modelRecyclerArrayList.get(i).getUser_name());
holder.workerid1.setText(String.valueOf(modelRecyclerArrayList.get(i).getWork_order_id()));
holder.description1.setText(modelRecyclerArrayList.get(i).getDescription());
holder.useraddress1.setText(modelRecyclerArrayList.get(i).getUser_address());
}
}
@Override
public int getItemCount() {
return modelRecyclerArrayList.size();
}
public class InProgressViewHolder extends RecyclerView.ViewHolder {
TextView location1,date1,username1,duration1,workerid1,description1,useraddress1
,tvorderid,tvdesc,tvusername,tvdate,tvlocation,tvdur,tvaddre,tvpay,tvamt,tvdt,tvcash,tvbal;
public InProgressViewHolder(@NonNull View itemView) {
super(itemView);
Typeface font = Typeface.createFromAsset(ctx.getAssets(),"fonts/Uber Move Text.ttf");
location1=itemView.findViewById(R.id.location1);
date1=itemView.findViewById(R.id.date1);
MainActivity.class
private void fetchInPro() {
RetrofitInterface jsonPostService = ServiceGenerator.createService(RetrofitInterface.class, "http://littletreasure.org.in/");
Call<InProgress_Response> call = jsonPostService.postRawJSON1();
call.enqueue(new Callback<InProgress_Response>() {
@Override
public void onResponse(Call<InProgress_Response> call, Response<InProgress_Response> response) {
if (response.isSuccessful()) {
proDialog.cancel();
List<Data_Inprogress> datumList1 = response.body().getData();
/*for (int i = 0; i < datumList.size(); i++) {
datumList.add(response.body().getData().get(i));
}*/
if (getActivity()!=null){
proDialog.cancel();
inProgress_adapter = new InProgress_Adapter(getContext(),datumList1);
recyclerView1.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
//recyclerView.setHasFixedSize(true);
//recyclerView.notify();
recyclerView1.setAdapter(inProgress_adapter);
}
}
}
这是我的回答。
{
"status": "Success",
"message": "10 results found.",
"data": [
{
"work_order_id": 1,
"description": "Desc-1",
"locaion": "Locaion-1",
"date": "0-01-2020",
"duration": "1 days",
"user_name": "User name-1",
"user_address": "User address-1",
"payment_details": [
{
"amount": 0,
"date": "0-01-2020",
"payment_method": "Cash",
"balance": 0
}
]
},
{
"work_order_id": 2,
"description": "Desc-2",
"locaion": "Locaion-2",
"date": "1-01-2020",
"duration": "2 days",
"user_name": "User name-2",
"user_address": "User address-2",
"payment_details": [
{
"amount": 1,
"date": "1-01-2020",
"payment_method": "Cash",
"balance": 2
}
]
},
{
"work_order_id": 3,
"description": "Desc-3",
"locaion": "Locaion-3",
"date": "2-01-2020",
"duration": "3 days",
"user_name": "User name-3",
"user_address": "User address-3",
"payment_details": [
{
"amount": 2,
"date": "2-01-2020",
"payment_method": "Cash",
"balance": 4
}
]
},
{
"work_order_id": 4,
"description": "Desc-4",
"locaion": "Locaion-4",
"date": "3-01-2020",
"duration": "4 days",
"user_name": "User name-4",
"user_address": "User address-4",
"payment_details": [
{
"amount": 3,
"date": "3-01-2020",
"payment_method": "Cash",
"balance": 6
}
]
},
{
"work_order_id": 5,
"description": "Desc-5",
"locaion": "Locaion-5",
"date": "4-01-2020",
"duration": "5 days",
"user_name": "User name-5",
"user_address": "User address-5",
"payment_details": [
{
"amount": 4,
"date": "4-01-2020",
"payment_method": "Cash",
"balance": 8
}
]
},
{
"work_order_id": 6,
"description": "Desc-6",
"locaion": "Locaion-6",
"date": "5-01-2020",
"duration": "6 days",
"user_name": "User name-6",
"user_address": "User address-6",
"payment_details": [
{
"amount": 5,
"date": "5-01-2020",
"payment_method": "Cash",
"balance": 10
}
]
},
{
"work_order_id": 7,
"description": "Desc-7",
"locaion": "Locaion-7",
"date": "6-01-2020",
"duration": "7 days",
"user_name": "User name-7",
"user_address": "User address-7",
"payment_details": [
{
"amount": 6,
"date": "6-01-2020",
"payment_method": "Cash",
"balance": 12
}
]
}
]
}
这是我的InProgress_Response(进行中响应)
public class InProgress_Response {
private String status;
private String message;
/*data list of response*/
private List<Data_Inprogress> data=null;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public List<Data_Inprogress> getData() {
return data;
}
public void setData(List<Data_Inprogress> data) {
this.data = data;
}
}
这是我的数据进行中
public class Data_Inprogress {
private String description;
private Integer work_order_id;
private String locaion;
private String date;
private String duration;
private String user_name;
private String user_address;
@SerializedName("payment_details")
@Expose
private List<Payment_Inprogress> paymentDetails=null;
public List<Payment_Inprogress> getPaymentDetails() {
return paymentDetails;
}
public void setPaymentDetails(List<Payment_Inprogress> paymentDetails) {
this.paymentDetails = paymentDetails;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getWork_order_id() {
return work_order_id;
}
public void setWork_order_id(int work_order_id) {
this.work_order_id = work_order_id;
}
public String getLocaion() {
return locaion;
}
public void setLocaion(String locaion) {
this.locaion = locaion;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
public String getUser_name() {
return user_name;
}
public void setUser_name(String user_name) {
this.user_name = user_name;
}
public String getUser_address() {
return user_address;
}
public void setUser_address(String user_address) {
this.user_address = user_address;
}
}
InProgress_Response
和Data_Inprogress
模型吗? - Md. Asaduzzaman