我的模型类中有两个包含整数值的arraylist.im在适配器中同时获取两个数组并比较它们的值。当第一个数组的任何值与第二个数组匹配时,然后在该特定列表行的列表中列出文本视图应为红色。Arraylist的大小可以增加和减小。
下面我要提供代码。请查看并提供解决方案。
public ArrayList<GetDoctorScheduleDetail> getDoctorScheduleDetails;// parent model class which is containing both bottom arraylist
public ArrayList<GetBlockedTimings> getBlockedTimingses = new ArrayList<>();
public ArrayList<AvailableTimeSlots> availableTimeSlotses = new ArrayList<>();
for (int i=0;i<getDoctorScheduleDetails.size();i++)
{
all_time_id = pojo.getAvailableTimeSlots().get(position).getTimeSlotId();
compare.add(all_time_id);
for (int j=0;j<getBlockedTimingses.size();j++) {
all_block_id = pojo.getGetBlockedTimings().get(position).getFkTimeId();
compare_fk.add(all_block_id);
if (all_time_id==all_block_id)
{
/* if (all_time_id==all_block_id)
{*/
Toast.makeText(context,"Hi It's matched"+i +""+j,Toast.LENGTH_SHORT).show();
Log.e("searching...1",+i+" "+j);
}
else if (all_time_id!=all_block_id) {
Toast.makeText(context,"No matched"+i +""+j,Toast.LENGTH_SHORT).show();
Log.e("searching...1",+i+" "+j);
}
/* Log.e("found_first_index: ", i + " second_index: " + j);
Log.e("searching... ",+i+" "+j);*/
}
}
模型类中没有第二个JSONarray值
public class MyScheduleJSONParser {
public static final String TAG = "MyScheduleJSONParser";
static ArrayList<GetDoctorScheduleDetail> doctorScheduleDetailList; // parent model array object
static List<AvailableTimeSlots> availableTimeSlotses;// child model array to save 1st json array values object
static List<GetBlockedTimings> getBlockedTimingses;// child model array to save 2nd json array values object
public static ArrayList<GetDoctorScheduleDetail> parseData(String content, int index) {
try {
JSONObject jsonObject = new JSONObject(content);
JSONArray details_jsonArray = jsonObject.getJSONArray("Detail");
doctorScheduleDetailList = new ArrayList<>();
availableTimeSlotses = new ArrayList<>();
getBlockedTimingses = new ArrayList<>();
JSONObject detailObject = details_jsonArray.getJSONObject(index);
// for (int i = 0; i <= detailObject.length(); i++) {
GetDoctorScheduleDetail slot = new GetDoctorScheduleDetail();//parent model class in this I'm storing other parameters rather then 2 jsonarry(AvailableTimeSlots,GetBlockedTimings)
slot.setDateOfSlot(detailObject.getString("DateOfSlot"));
slot.setScheduleId(detailObject.getInt("ScheduleId"));
slot.setBlockId(detailObject.getInt("BlockId"));
slot.setFkTimeId(detailObject.getInt("fkTimeId"));
slot.setDeleted(detailObject.getBoolean("IsDeleted"));
slot.setFkScheduledId(detailObject.getInt("fkScheduledId"));
slot.setUtcDateOfSlot(detailObject.getString("utcDateOfSlot"));
/* this is to fetch AvailableTimeSlots data*/
JSONArray availableTimeSlots = detailObject.getJSONArray("AvailableTimeSlots");
/* this loop for fetch AvailableTimeSlots data*/
for (int j = 0; j < availableTimeSlots.length(); j++) {
JSONObject innerDataObject = availableTimeSlots.getJSONObject(j);
AvailableTimeSlots timeSlots = new AvailableTimeSlots();//child model to save available array data
timeSlots.setTimeOfSlot(innerDataObject.getString("TimeOfSlot"));
timeSlots.setTimeSlotId(innerDataObject.getInt("TimeSlotId"));
timeSlots.setTimeofSlotDateTime(innerDataObject.getString("TimeofSlotDateTime"));
availableTimeSlotses.add(timeSlots);// adding data in child model list
slot.setAvailableTimeSlots(availableTimeSlotses);// adding data in parent model public void setAvailableTimeSlots(List<AvailableTimeSlots> availableTimeSlots){this.availableTimeSlots = availableTimeSlots;}
doctorScheduleDetailList.add(slot);// adding in parent list
}
/* this loop to fetch GetBlockedTimings data*/
if ((detailObject.getJSONArray("GetBlockedTimings")) != null) {
JSONArray getBlockedTimings = detailObject.getJSONArray("GetBlockedTimings");
/* this loop for fetch GetBlockedTimings data*/
for (int k = 0; k < getBlockedTimings.length(); k++) {
JSONObject getBlockedTimingsJSONObject = getBlockedTimings.getJSONObject(k);
GetBlockedTimings blockedTimings = new GetBlockedTimings();
blockedTimings.setFkTimeId(getBlockedTimingsJSONObject.getInt("fkTimeId"));
getBlockedTimingses.add(blockedTimings);// adding data in child model list
slot.setGetBlockedTimings(getBlockedTimingses);//adding data in parent model public void setGetBlockedTimings(List<GetBlockedTimings> getBlockedTimings){this.getBlockedTimings = getBlockedTimings;}
doctorScheduleDetailList.add(slot);// adding in parent list
}
//doctorScheduleDetailList.add(slot);
return doctorScheduleDetailList;
}
// }
} catch (JSONException e) {
e.printStackTrace();
}
return doctorScheduleDetailList;
}
}
答案 0 :(得分:0)
据我所知,您的问题就这样改变
all_time_id = pojo.getAvailableTimeSlots().get(position).getTimeSlotId();
compare.add(all_time_id);
all_block_id = pojo.getGetBlockedTimings().get(position).getFkTimeId();
compare_fk.add(all_block_id);
for (int j=0;j<compare_fk.size();j++) {
if(all_time_id = compare_fk.get(j)){
...........
else{
...........
}