0

how can I exchange new image with the currently image in selector.xml? for example this is my selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item 
    android:state_pressed="true" 
    android:drawable="@drawable/selected" />
<item 
    android:drawable="@drawable/unselected" />
</selector>

user will download a new image from server and the new image will exchange with the old. I.E: new_selected will download form server and exchange the selected. Thanks.

P/S: sorry about my bad english, hope you guys understand what I'm mean. apologize for any inconvenience. Thank you.

Regards,

Too

WynixToo
  • 161
  • 4
  • 15

1 Answers1

0

I have provided following solution since you are downloading image at runtime so you can not able to put it into the drawable folder so you must need to refer image by pahtname.

For doing this you need to write selector in code(I think so) as follow

OnTouchListener view1Touch = new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            v.setBackgroundDrawable(Drawable.createFromPath(pathName));
        }
        if (event.getAction() == MotionEvent.ACTION_UP) {
            v.setBackgroundDrawable(Drawable.createFromPath(pathName));
        }
        return true;
    }
};
Vivek
  • 4,170
  • 6
  • 36
  • 50
  • Hi HellBoy, another fammilar questioin here. how to I plug this function to listview? I had found a solution from [here](http://stackoverflow.com/questions/2217753/changing-background-color-of-listview-items-on-android), but the problem i facing now is the the list item was not changing the image when the listview item was out of screen. e.g: Listview have 20 items. But parent.getChildCount()==10, when the user selected item more than 10 den the image didn't change. sry about my bad english, hope u understand what I'm talking about. Thanks ^^ – WynixToo Jun 13 '11 at 10:12
  • I did not get you. If item is out of screen how you can click on it. If it is clickable why u r not writing code on itemclicklister. – Vivek Jun 17 '11 at 15:22