2012-03-20 6 views
1

나는 listview 안에 imageButton을 가지고 있으며 두 경우에 따라 이미지를 변경하려고합니다. 첫 번째 경우에는 이미지 버튼이 활성화되고 이미지가 있습니다. 두 번째 경우에는 이미지 버튼이 비활성화되고 다른 이미지가 있어야합니다.조건부로 imageButton 이미지 변경

public View getView(int position, View convertView, ViewGroup parent) { 

    View vi=convertView; 
    if(convertView==null) 
     vi = inflater.inflate(R.layout.list_row, null); 

    TextView title = (TextView)vi.findViewById(R.id.title); 
    TextView retail_price = (TextView)vi.findViewById(R.id.retail_price); 
    TextView deal_price = (TextView)vi.findViewById(R.id.deal_price); 
    TextView duration = (TextView)vi.findViewById(R.id.duration); 
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); 
    ImageButton imgb = (ImageButton)vi.findViewById(R.idIMGB); 

    HashMap<String, String> otherdeals = new HashMap<String, String>(); 
    otherdeals = data.get(position); 

    title.setText(otherdeals.get(dealsparsing.TAG_TITLE)); 
    retail_price.setText(otherdeals.get(dealsparsing.TAG_RETAIL)); 
    retail_price.setPaintFlags(retail_price.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); 
    deal_price.setText(otherdeals.get(dealsparsing.TAG_DEAL)); 
    duration.setText(otherdeals.get(dealsparsing.TAG_FINAL_TIME)); 
    Bitmap bitmap = DownloadImage(otherdeals.get(dealsparsing.TAG_IMAGE_URL)); 
    thumb_image.setImageBitmap(bitmap); 

    return vi; 

} 

답변

2

고유 한 (사용자 지정) 목록 어댑터를 정의해야합니다 (그렇지 않은 경우). 어댑터의 getView() 메소드에서 버튼을 활성화/비활성화하고 이미지를 변경합니다 (사례/조건에 따라 다름)

편집 : 코드를 편집하고 어댑터의 getView 메소드를 추가했습니다. 이제 문제가 어디 있습니까? 조건을 확인하고 ImageButton을 활성화/비활성화로 설정하고 이미지를 변경하십시오.

3

이와 같이 imageButton에 대한 사례 논리를 구현할 수 있습니다.

if(case1) 
{ 
imgb.setImageResource(R.drawable.enableImage); 
} 
if(case2) 
{ 
imgb.setImageResource(R.drawable.disableImage); 
} 
+0

(참여자> max_commands) getView하지만 일식 내 오류가 표시되면이 매개 변수를 사용하려고했습니다. –