vendredi 25 mars 2016

If statement inside for loop in android

I am creating Listview in my Android App.In My CustomAdapter I have anIf-statement inside a For loop. Let's see the Code.

public String[] timePartOne = {"10:00 AM", "10:30 AM", "11:00 AM", "11:30 AM"};
public boolean[] avaibleOne = {true, false, true, false};

in My CustomAdapter Class I have used this condition :

for(int i = 0; i < timePartOne.length;i++) {

                        if (avaibleOne[i] == true) {
                            holder.textview.setText(timePartOne[i]);
                            holder.textview.setTextColor(Color.parseColor("#0072BA"));
                        } else {
                            holder.textview.setText(timePartOne[i]);
                            holder.textview.setTextColor(Color.parseColor("#e6e6e6"));
                            holder.textview.setPaintFlags(holder.textview.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                        }

                }

But I don't know why this loop is continuously run. As per the review the loop will run 4 time. Because timePartOne.length is 4.

Any help be Appreciated.

Aucun commentaire:

Enregistrer un commentaire