I have a problem on how to display data i m getting from server using post request using retrofit. Here is my json data in which I want to display the "profile" in the recycler view. i m sending a string to server to get the data.
{
"status": 200,
"profile": {
"firstName": "nelli",
"lastName": "jhilmil",
"gender": "Female",
"addressLine": "Club",
"city": "Delhi",
"pincode": "560100",
"phoneNumber": "2423232344",
"userId": 50,
"createdByAdmin": false
}
}
This is the response json
public class ProfileResponse {
@SerializedName("status")
@Expose
private Status status;
@SerializedName("profile")
@Expose
private Profile profile;
getters and setters...
Below is child model class.
public class Profile {
@PrimaryKey
@SerializedName("userId")
@Expose
private Integer userId;
@SerializedName("firstName")
@ColumnInfo(name = "firstName")
private String firstName;
@SerializedName("surname")
@Expose
@ColumnInfo(name = "surname")
private String surname;
@SerializedName("gender")
@Expose
@ColumnInfo(name = "gender")
private String gender;
@SerializedName("phoneNumber")
@Expose
@ColumnInfo(name = "phoneNumber")
private String phoneNumber;
@SerializedName("addressLine")
@Expose
@ColumnInfo(name = "addressLine")
private String addressLine1;
@SerializedName("city")
@Expose
@ColumnInfo(name = "city")
private String city;
@SerializedName("pincode")
@Expose
@ColumnInfo(name = "pincode")
private String pincode;
@SerializedName("createbyAdmin")
@Expose
@ColumnInfo(name = "createbyAdmin")
private Boolean createdByAdmin;
getters and setters....
Below is the call wherein using post method sending a string to server to get the data
@POST("user/getProfile")
Call<ProfileResponse> getData(@Body JsonObject jsonObject);
Below is Adapter code where i have no idea what to send as a list to send as arraylist to send data to adapter
public class ProfileAdapter extends RecyclerView.Adapter<ProfileAdapter.ProfileViewHolder> {
private Context context;
private List<ProfileResponse> profiles;
public ProfileAdapter(Context context, List<ProfileResponse> profiles) {
this.context = context;
this.profiles = profiles;
}
@Override
public ProfileViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.get_profile_items, parent, false);
return new ProfileViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ProfileViewHolder holder, int position) {
This is my retrofit call to send and get data from server
jsonObj.addProperty("role", String.valueOf(ADMIN));
Call<ProfileResponse> profResponse = AppAuthClient.geVuAPIServices().getData(jsonObj);
profResponse.enqueue(new Callback<ProfileResponse>() {
@Override
public void onResponse(Call<ProfileResponse>call, retrofit2.Response<ProfileResponse>response) {
// mProgressBar.setVisibility(View.GONE);
if(response.isSuccessful() && response.body() != null) {
???????????
Toast.makeText(GetProfile.this, "success", Toast.LENGTH_SHORT);
}
I am getting the data from server but not able to send the fetched data from server to recyclerview. Would highly appreciate any help, thank you.
Updated question
this is how i initialized adapter in my activity
getData();
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
}