Hello, I'd like to ask you a question about rxAndroid. Hmm... I've been googling a lot, but I couldn't get the answer I wanted. ㅠ<
The result that I want is
class TempData{
Private String subject Nm;// separated by A, B, C, and D
private String subjectCode;
private int subjectDate;
}
ArrayList<TempData> data=new ArrayList<>();
data.add(new TempData("A","100",20161425);
data.add(new TempData("A","100",20161425);
data.add(new TempData("B","100",20161425);
data.add(new TempData("B","100",20161425);
data.add(new TempData("B","100",20161425);
data.add(new TempData("A","100",20161425);
data.add(new TempData("C","100",20161425);
data.add(new TempData("C","100",20161425);
Assuming your data will be like this
Observable.from(data).groupBy()...........................
In this way, I want to do ArrayList with subjectNm as "A," ArrayList with B as "ArrayList," and ArrayList with C, but I have no idea, so I'm asking you a question.
Please give us some advice
If you can use JAVA 8's Lambda-sik, I think you can do it as follows...
Observable.from(data).groupBy(item=>item.subjectNm);
If you don't want to use the Lambda expression, you can change the expression as follows.
Observable.from(data).groupBy(
new Func1<TeamData, String>() {
@Override
public String call(TeamData item) {
return item.subjectNm;
}
}
);
I don't know about rxAndroid, but why don't you just make a filtering method and use it? First, change the field of TempData to public and create this method.
ArrayList<TempData> filter(ArrayList<TempData>data, String name){
ArrayList<TempData> filteredData=new ArrayList<>();
for(TempData tempData:data){
if(tempData.subjectNm.equals(name)){
filteredData.add(tempData);
}
}
return filteredData;
}
Observable.from(filter(data,A")
I think we can use it like this.
I checked late crying Hmm.. I said I'll try to solve it
Map<Integer, List<TempDetailData>> groupedValues = new HashMap<>();
Observable.from(allData)
.groupBy(TempDetailData::getSubjectIndex).subscribe(go->
{
List<TempDetailData> groupValues = new ArrayList<>();
groupedValues.put(go.getKey(), groupValues);
go.subscribe(tempDetailData ->groupedValues.get(go.getKey()).add(tempDetailData));
});
Hmm.. I can't organize the sauce well That's how the group works, but it's kind of boring when you put the group of guys in the hash map
Thank you for your answer Haha
© 2024 OneMinuteCode. All rights reserved.