伙计们!我有一个问题,对于cycle.So,我有一个.I(),它遍历数据库中第三列的每个值(应该是日期格式),如果添加日期的月份与当前的month.The问题相同,我想要更改列表视图中项目的背景颜色-如果我使用下面的代码:
public void setItemRed(View view){
for(int i = 0 ; i <= myDB.getLastID() ; i++){
String date = myDB.getcol3(i);
String day = date.substring(0 , 2);
String month = date.substring(3 , 5);
String currentDate = currentDate();
String currentMonth = currentDate.substring(3 , 5);
listView.getChildAt(i).setBackgroundColor(Color.RED);
}
} 一切正常,当我添加if时,每一项都会显示红色的background.But:
public void setItemRed(View view){
for(int i = 0 ; i <= myDB.getLastID() ; i++){
String date = myDB.getcol3(i);
String day = date.substring(0 , 2);
String month = date.substring(3 , 5);
String currentDate = currentDate();
String currentMonth = currentDate.substring(3 , 5);
if(date.length() == 10){
if(month == currentMonth) {
listView.getChildAt(i).setBackgroundColor(Color.RED);
}
}
}
}它不会提前work.Thank你!
发布于 2017-08-14 15:33:55
每当比较两组字符串时,都需要使用.equals()命令。简单地使month == currentMonth不起作用并返回false。
因此,请尝试用month.equals(currentMonth)替换month == currentMonth。
希望这能有所帮助。
https://stackoverflow.com/questions/45669406
复制相似问题