android - Add image to buttons -
i have slidepuzzle plays numbers, want able make options play pictures. pictures in imageboard , dont know how make work. need in same class.
public void oncreate(bundle savedinstancestat) { super.oncreate(savedinstancestat); board = new board(); board.shuffleboard(); updatetiletext(); } public void updatetiletext() { setcontentview(r.layout.activity_game); string str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, str12, str13, str14, str15, str; button button1 = (button) findviewbyid(r.id.button1); button button2 = (button) findviewbyid(r.id.button2); button button3 = (button) findviewbyid(r.id.button3); button button4 = (button) findviewbyid(r.id.button4); button button5 = (button) findviewbyid(r.id.button5); button button6 = (button) findviewbyid(r.id.button6); button button7 = (button) findviewbyid(r.id.button7); button button8 = (button) findviewbyid(r.id.button8); button button9 = (button) findviewbyid(r.id.button9); button button10 = (button) findviewbyid(r.id.button10); button button11 = (button) findviewbyid(r.id.button11); button button12 = (button) findviewbyid(r.id.button12); button button13 = (button) findviewbyid(r.id.button13); button button14 = (button) findviewbyid(r.id.button14); button button15 = (button) findviewbyid(r.id.button15); button button = (button) findviewbyid(r.id.button); button1.setonclicklistener(this); button2.setonclicklistener(this); button3.setonclicklistener(this); button4.setonclicklistener(this); button5.setonclicklistener(this); button6.setonclicklistener(this); button7.setonclicklistener(this); button8.setonclicklistener(this); button9.setonclicklistener(this); button10.setonclicklistener(this); button11.setonclicklistener(this); button12.setonclicklistener(this); button13.setonclicklistener(this); button14.setonclicklistener(this); button15.setonclicklistener(this); button.setonclicklistener(this); str1 = string.valueof(board.gettile(0, 0)); str2 = string.valueof(board.gettile(0, 1)); str3 = string.valueof(board.gettile(0, 2)); str4 = string.valueof(board.gettile(0, 3)); str5 = string.valueof(board.gettile(1, 0)); str6 = string.valueof(board.gettile(1, 1)); str7 = string.valueof(board.gettile(1, 2)); str8 = string.valueof(board.gettile(1, 3)); str9 = string.valueof(board.gettile(2, 0)); str10 = string.valueof(board.gettile(2, 1)); str11 = string.valueof(board.gettile(2, 2)); str12 = string.valueof(board.gettile(2, 3)); str13 = string.valueof(board.gettile(3, 0)); str14 = string.valueof(board.gettile(3, 1)); str15 = string.valueof(board.gettile(3, 2)); str = string.valueof(board.gettile(3, 3)); button1 = (button) findviewbyid(r.id.button1); button1.settext(str1); button2 = (button) findviewbyid(r.id.button2); button2.settext(str2); button3 = (button) findviewbyid(r.id.button3); button3.settext(str3); button4 = (button) findviewbyid(r.id.button4); button4.settext(str4); button5 = (button) findviewbyid(r.id.button5); button5.settext(str5); button6 = (button) findviewbyid(r.id.button6); button6.settext(str6); button7 = (button) findviewbyid(r.id.button7); button7.settext(str7); button8 = (button) findviewbyid(r.id.button8); button8.settext(str8); button9 = (button) findviewbyid(r.id.button9); button9.settext(str9); button10 = (button) findviewbyid(r.id.button10); button10.settext(str10); button11 = (button) findviewbyid(r.id.button11); button11.settext(str11); button12 = (button) findviewbyid(r.id.button12); button12.settext(str12); button13 = (button) findviewbyid(r.id.button13); button13.settext(str13); button14 = (button) findviewbyid(r.id.button14); button14.settext(str14); button15 = (button) findviewbyid(r.id.button15); button15.settext(str15); button = (button) findviewbyid(r.id.button); button.settext(str); } public void imageboard(){ int[] duck = { r.drawable.duck_0, r.drawable.duck_1, r.drawable.duck_2, r.drawable.duck_3, r.drawable.duck_4, r.drawable.duck_5, r.drawable.duck_6, r.drawable.duck_7, r.drawable.duck_8, r.drawable.duck_9, r.drawable.duck_10, r.drawable.duck_11, r.drawable.duck_12, r.drawable.duck_13, r.drawable.duck_14, r.drawable.duck_15 }; } @override public void onclick(view v) { counter++; switch (v.getid()) { case r.id.button1: board.movetile(0, 0); updatetiletext(); break; case r.id.button2: board.movetile(0, 1); updatetiletext(); break; case r.id.button3: board.movetile(0, 2); updatetiletext(); break; case r.id.button4: board.movetile(0, 3); updatetiletext(); break; case r.id.button5: board.movetile(1, 0); updatetiletext(); break; case r.id.button6: board.movetile(1, 1); updatetiletext(); break; case r.id.button7: board.movetile(1, 2); updatetiletext(); break; case r.id.button8: board.movetile(1, 3); updatetiletext(); break; case r.id.button9: board.movetile(2, 0); updatetiletext(); break; case r.id.button10: board.movetile(2, 1); updatetiletext(); break; case r.id.button11: board.movetile(2, 2); updatetiletext(); break; case r.id.button12: board.movetile(2, 3); updatetiletext(); break; case r.id.button13: board.movetile(3, 0); updatetiletext(); break; case r.id.button14: board.movetile(3, 1); updatetiletext(); break; case r.id.button15: board.movetile(3, 2); updatetiletext(); break; case r.id.button: board.movetile(3, 3); updatetiletext(); break; }
simply use imagebutton
instead of button
.
Comments
Post a Comment