2012-03-20 16 views
1

私はlistviewの中にimageButtonを持っています.2つの場合に応じてイメージを変更したいと思います。最初のケースでは、画像ボタンが有効にされ、画像があります。後者の場合、イメージボタンは無効にされ、別のイメージを持つ必要があります。条件を変更して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

私はgetViewメソッドの内部で(参加者> max_commands)場合は、このparametreを使用しようとしたが、日食は私にエラーを表示 –

関連する問題