javaandroidlistviewanimationdrawable

drawable animation not workin


i want to use of animation drawable in my list but when i start the listActivity it crashs i have learned from this , when i remove this 2 animation codes

 AnimationDrawable frameAnimation = (AnimationDrawable) GamePic.getBackground();
        frameAnimation.start();

,it works animated by itself in my phone (p7 with android 4.4 ) but in other phones i have tried (asus memopad 7 , sony c ) it works with no animated drawables ! attent when i use of this up codes all phones just crashes below is my compelet code , what is wrong ?

public class MyList extends ListActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.games_list);

    setListAdapter(new AA());
}


@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

    Toast.makeText(MyList.this, "item" + position + "is clicked", Toast.LENGTH_SHORT).show();

}


class AA extends ArrayAdapter<String> {

    public AA() {
        super(MyList.this, R.layout.games_list_layout, Resources2.GameListArray);
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View row = convertView;
        if (row == null) {
            LayoutInflater inflater = getLayoutInflater();
            row = inflater.inflate(R.layout.games_list_layout, parent, false);
        }
        TextView GameName = (TextView) row.findViewById(R.id.textView1);
        ImageView GamePic = (ImageView) row.findViewById(R.id.imageView2);
        ImageView Cartridge = (ImageView) row.findViewById(R.id.imageView1);

        GameName.setText(Resources2.GameListArray[position]);
        GamePic.setImageResource(Resources2.GamePicArray[position]);
        Cartridge.setImageResource(Resources2.CartridgeFrame[Resources2.cartridgeColor[position]]);

        AnimationDrawable frameAnimation = (AnimationDrawable) GamePic.getBackground();
        frameAnimation.start();

        return row;

    }
}

}

thanks


Solution

  • i have found my problem !

    i had used GamePic.setImageResource(Resources2.GamePicArray[position]);

    but i should use

    GamePic.setBackgroundResource(Resources2.GamePicArray[position]);
    

    now it works fine !