Reputation: 67
[the green and red images should be in linear and must be displayed wit respective to the value in dotColors[]. ]
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
dotColors = datasource.getColorsArrayForWeek(tasks.get(position).getId(), call.get(Calendar.DAY_OF_YEAR));
LinearLayout tlli = (LinearLayout)v;
jj=0;
jj=0;
while(jj<7)
{
if(dotColors[jj]==0)
{
red=(ImageView) tlli.findViewById(R.id.day1);
}
else if(dotColors[jj]==1)
{
green=(ImageView) tlli.findViewById(R.id.day2);
}
jj++;
Log.i("jj::" +jj," ");
}
return v;
}
after querying from the database the values are stored in dotColors[]. dotColors[] contains integer elements whose values are only 0 and 1..
If the value is 0
I have to display "red"
image, if its 1
I have to display "green"
image. how can I achieve it?
Hope the explanation is much more clear now wid the image
Upvotes: 2
Views: 87
Reputation: 817
In your Layout set both image view visibility as android:visibility = "GONE" In your oncreate method
red=(ImageView) tlli.findViewById(R.id.day1);
green=(ImageView) tlli.findViewById(R.id.day2);
in condition
if(dotColors[jj]==0)
{
red.setVisibility(View.Visible);
red.setBackgroundResource(R.drawable.imageName)
//if ur image in folder res/drawable
}
else if(dotColors[jj]==1)
{
green.setVisibility(View.Visible);
green.setBackgroundResource(R.drawable.imageName1)
}
Upvotes: 1
Reputation: 11508
Is this that you want
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
dotColors = datasource.getColorsArrayForWeek(tasks.get(position).getId(), call.get(Calendar.DAY_OF_YEAR));
LinearLayout tlli = (LinearLayout)v;
jj=0;
while(jj<7)
{
if(dotColors[jj]==0)
{
red=(ImageView) tlli.findViewById(R.id.day1);
red.setImageResource(R.drawable.redImage);
}
else if(dotColors[jj]==1)
{
green=(ImageView) tlli.findViewById(R.id.day1);
green.setImageResource(R.drawable.greenImage);
}
jj++;
Log.i("jj::" +jj," ");
}
return v;
}
Upvotes: 0
Reputation: 45060
I think you want to be able to see the color changes. Your code executes so fast, that the changes are not visible and it directly lands up with the case where jj=76
. Add a Thread.sleep(millis)
in your code, to be able to see the changes.
jj = 0;
while (jj < 77) {
if(dotColors[jj]==0) {
// Do your red thingy.
} else {
// Do your green thingy.
}
try {
Thread.sleep(2000); // every 2 secs, you can see the change. Change as per your need
} catch (InterruptedException e) {
//Exception handling
}
Log.i("jj::" +jj," ");
jj++;
}
Upvotes: 0
Reputation: 10083
red=(ImageView)findViewById(R.id.yourimageviewid);
green=(ImageView)findViewById(R.id.yourimageviewid);
put this in oncreate()
use setImageBitmap() to setimages dynamically
Upvotes: 0