开发者

Android gallery onselecteditem

开发者 https://www.devze.com 2023-01-04 12:40 出处:网络
I am using gallery widget i want to change selected image. @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

I am using gallery widget i want to change selected image.

@Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    if(lastSeen != null){
       lastSeen.setImageResource(unselected image);
    }

    (ImageView(view)).setImageResource(selected image)
    lastSeen = view;
}

When i run the fo开发者_Python百科llowing code and i use roller ball or arrow keys over device and if i try to scroll left to right or right to left focus goes out of gallery to next item over the screen what is that ?


able to fix it by myself.

created xml item xlml file

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item  android:state_selected="true" 
                        android:drawable="@drawable/slider_se_icon_1101"/>
        <item android:drawable="@drawable/slider_un_icon_1101" />
</selector>

make sure selected and unselected images having same height and width else it will not work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号