有条件改变图像的ImageButton [英] Conditionally change imageButton image

查看:99
本文介绍了有条件改变图像的ImageButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListView内的ImageButton的,我想这取决于两种情况改变自己的形象。在第一种情况下的ImageButton启用并具有图像。在第二种情况下的的ImageButton被禁用,并且应该有不同的图像。

 公共查看getView(INT位置,查看convertView,父母的ViewGroup){    查看VI = convertView;
    如果(convertView == NULL)
        VI = inflater.inflate(R.layout.list_row,NULL);    TextView的标题=(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的持续时间=(TextView中)vi.findViewById(R.id.duration);
    ImageView的thumb_image =(ImageView的)vi.findViewById(R.id.list_image);
    的ImageButton IMGB =(的ImageButton)vi.findViewById(R.idIMGB);    HashMap的<字符串,字符串> otherdeals =新的HashMap<字符串,字符串>();
    otherdeals = data.get(位置);    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));
   位图的位图= DownloadImage(otherdeals.get(dealsparsing.TAG_IMAGE_URL));
   thumb_image.setImageBitmap(位图);    返回VI;}


解决方案

您需要定义自己的(自定义)列表适配器(如果你还没有)。在适配器的getView()方法中设置启用的按钮/ disbabled和更改图像(根据您的情况/条件)

编辑:您编辑您的code,并添加您的适配器的getView方法。现在问题出在哪里?检查您的状况和ImageButton的设置为启用/禁用并更改图片

I have an imageButton inside a listview and I want to change its image depending on two cases. In the first case the imagebutton is enabled and has an image. In the second case the imagebutton is disabled and should have a different image.

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;

} 

解决方案

You need to define your own (custom) list adapter (if you haven't). In adapter's getView() method you set your button enabled/disbabled and change the image (depending on your case/condition)

Edit: You edited your code and added your adapter's getView method. Now where is the problem? Check your condition and set the ImageButton to enabled/disabled and change the image

这篇关于有条件改变图像的ImageButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆