现在的情况为:我想通过执行一个方法后将某个ImageView的背景图片更换,附上代码:
public void changeTVChannel(String channelCode) {
                if (null != socketClient) {
                        //切台成功
//                        socketClient.sendDataToServerSocket(Const.DAOSHI_EPG_CHANGECHANNEL + ":" + channelCode);
                        Log.e("切台成功!", "切台成功!");
                        img_demand.setBackgroundResource(R.drawable.icon_tv_on);
                        icon_link.setVisibility(View.VISIBLE);
                        line.setVisibility(View.VISIBLE);
                }

程序跑完后,这里面的Log.e也打印了,下面2个控件也都显示了。就是img_demand的背景图片未更换。下面附上img_demand在xml中的布局:
<RelativeLayout>
       <TextView
                android:id="@+id/cctv_description"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/cctv_title"
                android:layout_marginLeft="100dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="5dp"
                android:layout_toLeftOf="@+id/img_demand"
                android:ellipsize="end"
                android:maxLines="2"
                android:text="啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊"
                android:textColor="#696969"
                android:textSize="18dp" />            <ImageView
                android:id="@+id/img_demand"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_alignParentRight="true"
                android:layout_marginRight="20dp"
                android:layout_marginTop="40dp"
                android:background="@drawable/icon_tv" />
</RelativeLayout>
请各位不吝指教以下小弟,不甚感激

解决方案 »

  1.   

    什么错误也没报吗,看好id别错了,试下这个试试?
    img_demand.setBackgroundDrawable(icon_tv_on);
      

  2.   

    你那写法你试过吗...setBackgroundDrawable()这里面是Drawable类型的,你放进去的一是系统找不到路径,二是类型也不对。
      

  3.   

    检查你的代码,看看是否在非主UI线程中操作,如果是的话就用Handle。。
    子线程更新UI会出现各种问题嘞~