Imagebutton change programmatically? Imagebutton change programmatically? android android

Imagebutton change programmatically?


your code is trying to change the background of the button. not its image.Those are two different things

  ((ImageButton) view).setImageResource(R.drawable.icon2);


Try this its working for me,Change the background image programmatically,

 image.setBackgroundResource(R.drawable.ico);


Hi you can use the following code

if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN ) {    ((ImageButton) view).setImageResource(getResources().getIdentifier("icon2", "drawable", getPackageName()));}else {    ((ImageButton) view).setImageDrawable(getDrawable(getResources().getIdentifier("icon2", "drawable", getPackageName())));}

Hope this will help you.