Android 如何使用改型使用compex json数据填充recyclerview?

Android 如何使用改型使用compex json数据填充recyclerview?,android,json,android-recyclerview,retrofit2,openweathermap,Android,Json,Android Recyclerview,Retrofit2,Openweathermap,请告知。我有一个复杂的json对象,我请求使用改型和GSONConverterFactory打开WeatherMapAPI。我无法请求5天的预测,我无法用数据填充我的Recyclerview,出现了一些问题。我无法在改型回调的onResponse方法中得到应该写的内容 改装请求都带有代码200和信息OK。所以麻烦不在这方面 提前谢谢你 下面是Json对象的结构 WeatherData是我解析Json时得到的根对象,请查找下面的代码。它(以及其他POJO)的所有代码都是从jsonschema2p

请告知。我有一个复杂的json对象,我请求使用改型和GSONConverterFactory打开WeatherMapAPI。我无法请求5天的预测,我无法用数据填充我的Recyclerview,出现了一些问题。我无法在改型回调的onResponse方法中得到应该写的内容

改装请求都带有代码200和信息OK。所以麻烦不在这方面

提前谢谢你

下面是Json对象的结构

WeatherData是我解析Json时得到的根对象,请查找下面的代码。它(以及其他POJO)的所有代码都是从jsonschema2pojo导入的:

public class WeatherData {

@SerializedName("coord")
@Expose
private Coord coord;
@SerializedName("weather")
@Expose
private List<Weather> weather = null;
@SerializedName("base")
@Expose
private String base;
@SerializedName("main")
@Expose
private Main main;
@SerializedName("visibility")
@Expose
private Integer visibility;
@SerializedName("wind")
@Expose
private Wind wind;
@SerializedName("clouds")
@Expose
private Clouds clouds;
@SerializedName("dt")
@Expose
private Long dt;
@SerializedName("sys")
@Expose
private Sys sys;
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("name")
@Expose
private String name;
@SerializedName("cod")
@Expose
private Integer cod;

public Coord getCoord() {
    return coord;
}

public void setCoord(Coord coord) {
    this.coord = coord;
}

public List<Weather> getWeather() {
    return weather;
}

public void setWeather(List<Weather> weather) {
    this.weather = weather;
}

public String getBase() {
    return base;
}

public void setBase(String base) {
    this.base = base;
}

public Main getMain() {
    return main;
}

public void setMain(Main main) {
    this.main = main;
}

public Integer getVisibility() {
    return visibility;
}

public void setVisibility(Integer visibility) {
    this.visibility = visibility;
}

public Wind getWind() {
    return wind;
}

public void setWind(Wind wind) {
    this.wind = wind;
}

public Clouds getClouds() {
    return clouds;
}

public void setClouds(Clouds clouds) {
    this.clouds = clouds;
}

public Long getDt() {
    return dt;
}

public void setDt(Long dt) {
    this.dt = dt;
}

public Sys getSys() {
    return sys;
}

public void setSys(Sys sys) {
    this.sys = sys;
}

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Integer getCod() {
    return cod;
}

public void setCod(Integer cod) {
    this.cod = cod;
}
公共类天气数据{
@序列化名称(“协调”)
@暴露
私人合作社;
@序列化名称(“天气”)
@暴露
私有列表天气=空;
@序列化名称(“基”)
@暴露
私有字符串基;
@序列化名称(“主”)
@暴露
私人主楼;
@序列化名称(“可见性”)
@暴露
私有整数可见性;
@序列化名称(“风”)
@暴露
私人风;
@序列化名称(“云”)
@暴露
私密的云朵;
@序列化名称(“dt”)
@暴露
私人长dt;
@序列化名称(“sys”)
@暴露
私有系统;
@序列化名称(“id”)
@暴露
私有整数id;
@序列化名称(“名称”)
@暴露
私有字符串名称;
@序列化名称(“cod”)
@暴露
私有整数cod;
公共合作社{
返回坐标;
}
公共无效设置坐标(坐标坐标坐标){
this.coord=coord;
}
公共列表getWeather(){
回归天气;
}
公众天气(列出天气){
这个天气=天气;
}
公共字符串getBase(){
返回基地;
}
公共无效收进框(字符串基){
this.base=base;
}
公共Main getMain(){
回水总管;
}
公共无效设置主(主){
this.main=main;
}
公共整数getVisibility(){
返回能见度;
}
公共void集合可见性(整数可见性){
这个.可见性=可见性;
}
公共风{
回风;
}
公共空间风(风){
风=风;
}
公共云getClouds(){
回归云;
}
公共云(云){
云=云;
}
公共长getDt(){
返回dt;
}
公共无效设置(长设置){
这1.dt=dt;
}
公共系统getSys(){
返回系统;
}
公共无效设置系统(Sys Sys){
this.sys=sys;
}
公共整数getId(){
返回id;
}
公共无效集合id(整数id){
this.id=id;
}
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
公共整数getCod(){
返回cod;
}
公共void setCod(整数cod){
this.cod=cod;
}
这是我的RecyclerView.适配器

public class Forecast5DaysAdapter extends RecyclerView.Adapter<Forecast5DaysAdapter.ForecastHolder> {



List<WeatherData> mWeatherDataList;


public static class ForecastHolder extends RecyclerView.ViewHolder {

    public TextView dateOnDate;
    public ImageView weatherOnDate;
    public TextView tempOnDate;
    public TextView windSpeedOnDate;

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

        dateOnDate = (TextView) view.findViewById(R.id.dateOnDate);
        windSpeedOnDate = (TextView) view.findViewById(R.id.windSpeedOnDate);
        tempOnDate = (TextView) view.findViewById(R.id.tempOnDate);
        weatherOnDate = (ImageView) view.findViewById(R.id.imageOnDate);


    }
}

public Forecast5DaysAdapter(List<WeatherData> mWeatherDataList) {

    this.mWeatherDataList = mWeatherDataList;
}

@Override
public ForecastHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.forecast_card, parent, false);

    final ForecastHolder forecastHolder = new ForecastHolder(view);

    return forecastHolder;
}

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

    //FILLING THE CARDS IN RECYCLERVIEW WITH INFORMATION

    holder.dateOnDate.setText(mWeatherDataList.get(position).getDt().toString());
    holder.tempOnDate.setText(mWeatherDataList.get(position).getMain().getTemp().toString());
    holder.windSpeedOnDate.setText(mWeatherDataList.get(position).getWind().getSpeed().toString());
    Picasso.with(holder.weatherOnDate.getContext()).load("http://openweathermap.org/img/w/" + mWeatherDataList.get(position).getWeather().get(position).getIcon() + ".png").into(holder.weatherOnDate);

}


@Override
public int getItemCount() {
    return 0;
}
public类Forecast5DaysAdapter扩展了RecyclerView.Adapter{
列表mWeatherDataList;
公共静态类Forecasholder扩展了RecyclerView.ViewHolder{
公共文本视图日期;
公共图像视图weatherOnDate;
公共文本视图tempOnDate;
公共文本视图windSpeedOnDate;
公共预测者(视图){
超级(视图);
dateOnDate=(TextView)view.findViewById(R.id.dateOnDate);
windSpeedOnDate=(TextView)view.findViewById(R.id.windSpeedOnDate);
tempOnDate=(TextView)view.findViewById(R.id.tempOnDate);
weatherOnDate=(ImageView)view.findViewById(R.id.imageOnDate);
}
}
公共预报室5daysadapter(列表mWeatherDataList){
this.mWeatherDataList=mWeatherDataList;
}
@凌驾
public ForecashHolder onCreateViewHolder(视图组父级,int-viewType){
View=LayoutInflater.from(parent.getContext())
.充气(R.layout.forecast_卡,父级,假);
最终预报员预报员=新预报员(视图);
归还抵押品赎回权;
}
@凌驾
BindViewHolder上的公共无效(止赎持有人,内部位置){
//用信息填充RECYCLERVIEW中的卡片
holder.dateOnDate.setText(mWeatherDataList.get(position.getDt().toString());
holder.tempOnDate.setText(mWeatherDataList.get(position.getMain().getTemp().toString());
holder.windSpeedOnDate.setText(mWeatherDataList.get(position.getWind().getSpeed().toString());
毕加索.with(holder.weatherOnDate.getContext()).load(“http://openweathermap.org/img/w/“+mWeatherDataList.get(position).getWeather().get(position).getIcon()+”.png”).into(holder.weatherOnDate);
}
@凌驾
public int getItemCount(){
返回0;
}
下面是我想显示Recyclerview的类

public class Forecast5Days extends AppCompatActivity {

private static final String API_KEY = "HERE IS THE KEY";

private RecyclerView forecastRecycler;
private ArrayList<WeatherData> mWeatherData;
private Forecast5DaysAdapter forecast5DaysAdapter;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_forecast_5_days);

    forecastRecycler = (RecyclerView) findViewById(R.id.forecast_5_daysRecycler);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
    forecastRecycler.setLayoutManager(layoutManager);
    final Forecast5DaysAdapter forecast5DaysAdapter = new Forecast5DaysAdapter(mWeatherData);

    forecastRecycler.setAdapter(forecast5DaysAdapter);



    Intent intent = getIntent();
    final String cityName = intent.getStringExtra("cityName");

    if (!cityName.isEmpty()) {
        Call<WeatherData> call = RetrofitBuilderHelper.weatherAPI.getForecast5Days(cityName, "ru", "metric", API_KEY);

        call.enqueue(new Callback<WeatherData>() {
            @Override
            public void onResponse(Call<WeatherData> call, Response<WeatherData> response) {

                    //????????????????

            }

            @Override
            public void onFailure(Call<WeatherData> call, Throwable t) {
                Toast toast = Toast.makeText(Forecast5Days.this, "Something went wrong with request", Toast.LENGTH_LONG);
                toast.show();
            }
        });

    } else {
        Toast toast = Toast.makeText(Forecast5Days.this, "Something went wrong with intent", Toast.LENGTH_LONG);
        toast.show();

    }


}
公共类预测活动5天{
私有静态最终字符串API_KEY=“这里是密钥”;
私人垃圾回收站;
私有ArrayList mWeatherData;
私人预报员5天预报员5天预报员;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u forecast\u 5天);
ForecasterCycle=(RecyclerView)findViewById(R.id.forecast\u 5天循环器);
RecyclerView.LayoutManager LayoutManager=新的LinearLayoutManager(getApplicationContext());
setLayoutManager(layoutManager);
最终预报5daysadapter预报5daysadapter=新预报5daysadapter(mWeatherData);
forecastRecycler.setAdapter(forecast5DaysAdapter);
Intent=getIntent();
最终字符串cityName=intent.getStringExtra(“cityName”);
如果(!cityName.isEmpty()){
Call Call=ReformationBuilderHelper.weatherAPI.getForecast5Days(城市名称,“ru”,“公制”,API_键);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
//????????????????
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
Toast Toast=Toast.makeText(Forecast5Days.this,“请求出错”,Toast.LENGTH\u LONG);
toast.show();
}
});
}否则{
Call<List<WeatherData>> call = RetrofitBuilderHelper.weatherAPI.getForecast5Days(cityName, "ru", "metric", API_KEY);

        call.enqueue(new Callback<List<WeatherData>>() {
@Override
public void onResponse(Call<List<WeatherData>> call, Response<List<WeatherData>> response) {
    forecastRecycler.weatherList = response.body();
    forecastRecycler.notifyDatasetChanged();
}
   call.enqueue(new Callback<WeatherData>() {
        @Override
        public void onResponse(Call<WeatherData> call, Response<WeatherData> response) {

           if(response.isSuccessful() && response.body != null) {
                WeatherData data = response.body();
           }

        }

        @Override
        public void onFailure(Call<WeatherData> call, Throwable t) {
            Toast toast = Toast.makeText(Forecast5Days.this, "Something went wrong with request", Toast.LENGTH_LONG);
            toast.show();
        }
    });
      call.enqueue(new Callback<WeatherData>() {
    @Override
    public void onResponse(Call<WeatherData> call, Response<WeatherData> response) {

       if(response.isSuccessful() && response.body != null) {
            WeatherData data = response.body();
            List<Weather> weatherList = data.getWeatherList(); 
           //Pass this list to your adapter
       }

    }

    @Override
    public void onFailure(Call<WeatherData> call, Throwable t) {
        Toast toast = Toast.makeText(Forecast5Days.this, "Something went wrong with request", Toast.LENGTH_LONG);
        toast.show();
    }
});