2013-04-02 2 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 인 경우 이미지를 "green" 이미지로 표시해야하는 경우 "red" 이미지를 표시해야합니다. 나는 어떻게 그것을 성취 할 수 있는가? 이제 이미지를 떨어 졌 설명은 훨씬 더 분명 희망

+0

하루에 ImageView를 초기화 할 때마다? –

+0

빨강과 초록색은 같은 이미지 참조를 가지고 있습니다. 달성하려는 것은 무엇입니까? jj 값을 기준으로 이미지 뷰의 이미지를 변경하고 싶습니까? – Pragnani

+0

이렇게 빨리 일어날 것입니다. 여러분이 볼 수있는 것은'jj = 76'의 결과입니다. 실제로 당신이 성취하고자하는 것은 무엇입니까? – SudoRahul

답변

0

빨간색 = (이미지 뷰) findViewById를 (R.id.yourimageviewid);

녹색 = (ImageView) findViewById (R.id.yourimageviewid);

에서 OnCreate()

사용 setImageBitmap에 넣어이()에 setimages 동적

+0

@arju ..이 yar를 시도해 보겠습니다. – AnRu

+0

red.setImageBitmap (BitmapFactory.decodeResource (this.getResources() , R.drawable.적색)); "getResources()"오류가 발생했습니다 – AnRu

+0

이 수정되었습니다. 그러나 그것이 일하지 않는 stil !! : – 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

ohh보다 내가 틀렸어. 레이아웃 화면 샷 또는 일부 종이 도면을 보여 주실 수 있습니다. 또는 내가 원하는 그림을 그릴 수 있습니다. 도와 드리겠습니다. –

+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) 

    } 
관련 문제