How Can I Handle Images And Change There Function?
Hi i'm very new to android and tried to ask this question recently, but nobody understood what the hell i was talking about and looking at it myself i'm not surprised, (kinda made
Solution 1:
So you want to change the drawable ResourceR.drawable.i_feel
to be a different image?
I'm afraid, that's not possible. Android gives every image in the drawables
folder a unique Id.
If there should be specific sets of images been shown in the bottom container, you'll need to create an array for every set.
I'd recommend you to change the OnClickListener a bit. You can change it into this:
private View.OnClickListenerButtonClickListener=newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
ImageButtonclickedButton= (ImageButton) v;
DrawablelatestDrawable= clickedButton.getDrawable();
switch (v.getId()) {
case R.id.imageButton:
speak = 2;
if (speak == 2) {
btn1.setImageResource(R.drawable.to_play);
btn2.setImageResource(R.drawable.to_eat);
btn3.setImageResource(R.drawable.a_drink);
btn4.setImageResource(R.drawable.a_hug);
setImageButtonVisibilities();
btnmt1.setImageDrawable(latestDrawable);
btnmt1.setVisibility(View.VISIBLE);
}
break;
case R.id.imageButton2:
speak = 3;
if (speak == 3) {
btn1.setImageResource(R.drawable.friends);
btn2.setImageResource(R.drawable.music);
btn3.setImageResource(R.drawable.sports);
btn4.setImageResource(R.drawable.emptypuzzlepiece);
btn5.setImageResource(R.drawable.emptypuzzlepiece);
setImageButtonVisibilities();
btnmt1.setImageDrawable(latestDrawable);
btnmt1.setVisibility(View.VISIBLE);
}
break;
case R.id.imageButton3:
speak = 4;
if (speak == 4) {
btn1.setImageResource(R.drawable.sad);
btn2.setImageResource(R.drawable.happy);
btn3.setImageResource(R.drawable.sick);
setImageButtonVisibilities();
btnmt1.setImageDrawable(latestDrawable);
btnmt1.setVisibility(View.VISIBLE);
}
}
}
privatesetImageButtonVisibilities() {
if(btn1.getDrawable == null)
btn1.setVisibility(View.INVISIBLE);
else
btn1.setVisibility(View.VISIBLE);
if(btn2.getDrawable == null)
btn2.setVisibility(View.INVISIBLE);
else
btn2.setVisibility(View.VISIBLE);
if(btn3.getDrawable == null)
btn3.setVisibility(View.INVISIBLE);
else
btn3.setVisibility(View.VISIBLE);
if(btn4.getDrawable == null)
btn4.setVisibility(View.INVISIBLE);
else
btn4.setVisibility(View.VISIBLE);
if(btn5.getDrawable == null)
btn5.setVisibility(View.INVISIBLE);
else
btn5.setVisibility(View.VISIBLE);
if(btn6.getDrawable == null)
btn6.setVisibility(View.INVISIBLE);
else
btn6.setVisibility(View.VISIBLE);
}
}
This will always put the Drawable
of the pressed ImageButton
as Drawable for the ImageButton in the top container.
The new method is just helping with the Visibility changes you do in any case
statement. You'll need to call it everytime you changed the Drawables. you cn copy and paste it in in the class as well...
I hope this helps you a bit.
Post a Comment for "How Can I Handle Images And Change There Function?"