简体   繁体   中英

Date showing null or nothing in multiple view type recycler view

Loading a list from Json the model is:

message: success
ResponseData": [
    {
        "RecordEntryOn": "2022-01-25T00:00:00",
        "PatientID": 4934,
        "DiscountedAmount": 1380248.0,
        "ClientID": 0,
        "TestType": "Test",
        "TestName": null,
        "fetchingTime": "0001-01-01T00:00:00",
        
    },
{
        "RecordEntryOn": "2022-01-25T00:00:00",
        "PatientID": 1605,
        "DiscountedAmount": 446590.0,
        "ClientID": 0,
        "TestType": "Test",
        "TestName": "Custom package",
        "fetchingTime": "0001-01-01T00:00:00",
        
    },
.....//more entries////

Kindly look carefully the first record represents total revenue for the date and than the normal list by test name in first record TestName is null and than all entires have a test name. The first record of list is total revenue for the selected date (selected from calendar)

I have to display the first entry as

**Date : Revenue :**

and than the normal list as

**Test Name:  Revenue: Patient Count:**

I used multiple view to achieve the same everything is working fine but the Date in first entry is not showing, Revenue is showing correctly I tried:

textview1.setText(String.valueof(response.getRecordyEntryOn());
Result of above is Date : null

If I am formatting it as simple date format than it is showing nothing

Date :

like above

This is how i am defining RecordyEntry in model:

@SerializedName("RecordEntryON")
@Expose
private Date record_EntryOn;

public Date getRecord_EntryOn() {
    return record_EntryOn;
}

My getItemView in adapter:

public int getItemViewType(int position) {


    if ((testResponseList.get(position).getTest_Name()) == null) {
        return revenue_list;
    } else
        return main_list;
}

revenue_list is for Total revenue part where I want to show Revenue and date only

main_list is the layout where i am showing all other fields

whats the issue here I am not figuring it out kindly help

In your model class, you've used @SerializedName("RecordEntryON") . Note the ON in caps, but in the response, the key is "RecordEntryOn", (Small case n).

Try this:

@SerializedName("RecordEntryOn")
@Expose
private Date record_EntryOn;

public Date getRecord_EntryOn() {
    return record_EntryOn;
}

Edit: Take a look at this link for formatting your date.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM