0
人!私はcycle.Soに問題があります。私はfor()データベースからの3番目の列のすべての値を通過する(これは、日付形式であることになっています)。私はlistviewからアイテムの背景色を変更したい現在month.Theの問題があるとして追加日付の月は同じである - 私はこのようなコードを使用する場合:サイクルとif文について
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);
}
}
をすべてが動作し、私があれば追加したときに、すべての項目が赤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);
}
}
}
}
これは動作しません。事前におねがいします!
あなたのインデントをif文でソートしてみてください。 –
'month == currentMonth'は常にfalseを返します。代わりに 'month.eqauals(currentMonth)'を使用してください – mihail
mihailありがとう!しかし、重要なのはなぜそれが常に偽に戻るのかということです。 – Goshoy