2

在此处输入图像描述[绿色和红色图像应该是线性的,并且必须根据 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;
    }

从数据库查询后,值存储在 dotColors[] 中。dotColors[] 包含整数元素,其值为仅0 and 1..如果值是0我必须显示"red"图像,如果它1我必须显示"green"图像。我怎样才能实现它?希望现在图像中的解释更加清楚

4

4 回答 4

1

在您的布局中将两个图像视图可见性设置为 android:visibility = "GONE" 在您的 oncreate 方法中

    red=(ImageView) tlli.findViewById(R.id.day1);
    green=(ImageView) tlli.findViewById(R.id.day2);

状况良好

   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)

    }
于 2013-04-02T10:32:47.717 回答
0

我想你希望能够看到颜色的变化。您的代码执行得如此之快,以至于更改不可见,并且直接与jj=76. 在您的代码中添加一个Thread.sleep(millis),以便能够看到更改。

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++;
}
于 2013-04-02T06:45:33.857 回答
0

红色=(ImageView)findViewById(R.id.yourimageviewid);

green=(ImageView)findViewById(R.id.yourimageviewid);

把它放在 oncreate()

使用 setImageBitmap() 动态设置图像

于 2013-04-02T06:35:03.183 回答
0

这是你想要的吗

@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;
    }
于 2013-04-02T06:52:02.680 回答