2013-04-02 29 views
2

enter image description here [绿色和红色图像应该是线性的,必须分别显示为dotColors []中的值。 ]android多次使用图像

@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"图像。我怎么能实现它? 希望现在的解释更清晰图像

+0

每次你用day1初始化ImageView? –

+0

红色和绿色具有相同的图像引用..你想实现什么,你想要改变基于jj值的imageview图像..? – Pragnani

+0

这会发生得如此之快,你只能看到'jj = 76'的结果。你究竟想要达到什么目标? – SudoRahul

回答

0

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

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

把这个OnCreate中()

使用setImageBitmap()来setimages动态

+0

@arju ..我会尝试这个yar .. – AnRu

+0

我使用了下面的代码。red.setImageBitmap(BitmapFactory.decodeResource(this.getResources() ,可提款。红色));我得到错误“getResources()” – AnRu

+0

纠正。但它仍然不起作用! :( – AnRu

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++; 
} 
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; 
    } 
+0

这不起作用:( – AnRu

+0

哦,比我必须弄错你能给我看你的布局屏幕截图或一些纸张绘图或油漆图像,我想要这些帮助你 –

+0

请提高马声誉2 :(所以我可以发布图像!! – AnRu

1

在布局设置这两个图像视图能见度 机器人:知名度= “水涨船高” 在你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) 

    }