android多次使用图像

时间:2013-04-02 06:26:03

标签: android

enter image description here [绿色和红色图像应该是线性的,必须与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 个答案:

答案 0 :(得分: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)

    }

答案 1 :(得分:0)

  

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

     

绿色=(ImageView的)findViewById(R.id.yourimageviewid);

把它放在oncreate()

使用setImageBitmap()动态搜索

答案 2 :(得分: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++;
}

答案 3 :(得分: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;
    }