如何将嵌套的HashMap对象显示到RecyclerView?

时间:2017-05-08 00:47:39

标签: android hashmap android-recyclerview recycler-adapter

我正在尝试向RecyclerView显示数据。实际上我想在不同的HashMap中显示3个不同的对象到RecyclerView,但是如果我知道如何用1来做它可能会得到怎么做。

json格式化的方式我不得不使用HashMaps。看看这个 你在哪里使用圆形颜色,这是我需要的数据

enter image description here

现在我不知道我是否错误地使用了Modelclasses,但是这里是他们在这里工作,因为我可以获得正确的数据显示在日志文件中我只是不知道如何将它放在我删除的RecyclerView中这里的Model类Movie类中有一些信息,因为你可以看到它们并不重要,只会使页面变长。

public class Movie implements Parcelable {

@SerializedName("pid")
String movieId;

@SerializedName("idioma")
HashMap<String, MovieLanguage> movielanguages;

public Movie() {
}

public Movie(String movieId, HashMap<String, MovieLanguage> movielanguages) {
    this.movieId = movieId;

    this.movielanguages = movielanguages;
}


public String getMovieId() {
    return movieId;
}


public void setMovieId(String movieId) {
    this.movieId = movieId;
}




public HashMap<String, MovieLanguage> getMovieLanguage() {
    return movielanguages;
}
public void setMovieLanguage(HashMap<String, MovieLanguage> movielanguages) {
    this.movielanguages = movielanguages;
}

另一个模特课:

public class MovieLanguage implements Parcelable {


@SerializedName("formatos")
HashMap<String, MovieFormat> movieformats;


public HashMap<String, MovieFormat> getMovieFormat() {
    return movieformats;
}
public void setMovieFormat(HashMap<String, MovieFormat> movieformats) {
    this.movieformats = movieformats;
}

这是另一个模型类:

public class MovieFormat implements Parcelable {

@SerializedName("fechas")
HashMap<String, MovieDate> moviedates;


public HashMap<String, MovieDate> getMovieDate() {
    return moviedates;
}
public void setMovieDate(HashMap<String, MovieDate> moviedates) {
    this.moviedates = moviedates;
}

这是最后一个模型类:

public class MovieFunction implements Parcelable {


@SerializedName("session-status")
String functionStatus;
@SerializedName("session-time")
String functionTime;



public String getFunctionStatus() {
    return functionStatus;
}


public void setFunctionStatus(String functionStatus) {
    this.functionStatus = functionStatus;
}

public String getFunctionTime() {
    return functionTime;
}


public void setFunctionTime(String functionTime) {
    this.functionTime = functionTime;
}

以下是我在活动中使用的代码,用于获取我需要显示的正确信息的日志。我只需要有人指出/帮助我正确的方向,在RecyclerView中显示它们。

for (Map.Entry<String, MovieLanguage> entry : mymovie.getMovieLanguage().entrySet()){
        HashMap<String, MovieFormat> movieformatw = entry.getValue().getMovieFormat();

        for (Map.Entry<String, MovieFormat> entry2 : movieformatw.entrySet()) {
            HashMap<String, MovieDate> moviedatesw = entry2.getValue().getMovieDate();


        Log.d("Header", entry.getKey()+ " " + entry2.getKey());


            for (Map.Entry<String, MovieDate> entry3 : moviedatesw.entrySet()){
                HashMap<String, MovieFunction> moviefunctionsw = entry3.getValue().getMovieFunction();

                if(entry3.getKey().contains(today)){
                    // checks if date is today and display data


                    for(Map.Entry<String, MovieFunction> entry4 : moviefunctionsw.entrySet()){



                        Log.d("movietimes ",  "" + entry4.getValue().getFunctionTime());


                    }


                }
                else{

                    // there are currently no movie for today do nothing

                }


            }

        }

    }

如果我运行上面的代码,我会得到以下数据,我还需要以正确的方式在RecyclerView中显示的内容

D/header: Subt Spanish DBOX-2D
D/movietimes:  7:00PM
D/movietimes:  9:30PM
D/movietimes:  4:30PM
D/movietimes:  2:00PM
D/header: Subtitulada DBOX-2D
D/movietimes:  7:00PM
D/movietimes:  9:30PM
D/movietimes:  4:30PM
D/movietimes:  2:00PM
D/header: DBOX DBOX-2D
D/movietimes:  7:00PM
D/movietimes:  9:30PM
D/movietimes:  4:30PM
D/movietimes:  2:00PM

0 个答案:

没有答案