【发布时间】:2023-03-28 23:25:01
【问题描述】:
这里 daysofInterest 为 ["Tuesday","Thursday","Friday","Friday"] 像这样,我使用 daysArray 将该字符串拆分为 "," 并检查数组,但我没有得到我想要的结果,请你修复它。并得到这样的 daysArray [Ljava.lang.String;@e856c3b
String daysOfInterest=map.get("daysOfinterest");
Log.d("DAYS OF INTEREST",daysOfInterest);
String[] daysArray = daysOfInterest.split(",");
Log.d("DAYS",daysArray.toString());
for(int i=0;i<daysArray.length;i++){
if(daysArray[i].equalsIgnoreCase("sunday")){
tvSunday.setBackground(ContextCompat.getDrawable(ActivitySavedCareAlerts.this,R.drawable.style_circle_filled_green));
tvSunday.setTextColor(ContextCompat.getColorStateList(getApplicationContext(),R.color.white));
}
if(daysArray[i].equalsIgnoreCase("monday")){
tvMonday.setBackground(ContextCompat.getDrawable(ActivitySavedCareAlerts.this,R.drawable.style_circle_filled_green));
tvMonday.setTextColor(ContextCompat.getColorStateList(getApplicationContext(),R.color.white));
}
if(daysArray[i].equalsIgnoreCase("tuesday")){
tvTuesday.setBackground(ContextCompat.getDrawable(ActivitySavedCareAlerts.this,R.drawable.style_circle_filled_green));
tvTuesday.setTextColor(ContextCompat.getColorStateList(getApplicationContext(),R.color.white));
}
if(daysArray[i].equalsIgnoreCase("wednesday")){
tvWednesDay.setBackground(ContextCompat.getDrawable(ActivitySavedCareAlerts.this,R.drawable.style_circle_filled_green));
tvWednesDay.setTextColor(ContextCompat.getColorStateList(getApplicationContext(),R.color.white));
}
if(daysArray[i].equalsIgnoreCase("thursday")){
tvThursday.setBackground(ContextCompat.getDrawable(ActivitySavedCareAlerts.this,R.drawable.style_circle_filled_green));
tvThursday.setTextColor(ContextCompat.getColorStateList(getApplicationContext(),R.color.white));
}
if(daysArray[i].equalsIgnoreCase("friday")){
tvFriday.setBackground(ContextCompat.getDrawable(ActivitySavedCareAlerts.this,R.drawable.style_circle_filled_green));
tvFriday.setTextColor(ContextCompat.getColorStateList(getApplicationContext(),R.color.white));
}
if(daysArray[i].equalsIgnoreCase("saturday")){
tvSaturday.setBackground(ContextCompat.getDrawable(ActivitySavedCareAlerts.this,R.drawable.style_circle_filled_green));
tvSaturday.setTextColor(ContextCompat.getColorStateList(getApplicationContext(),R.color.white));
}
}
return convertView;
}
【问题讨论】:
-
使用 else if 而不是 if
-
有两个错误
-
请问你能指出我的错误吗?
-
我说的你试过了吗
标签: java android arrays string textview