hi im still very new to android but have been developing this part of my app for a while with little progress, the idea is I have 2 containers, a top container with INVISIBLE imageButtons inside it, and a bottom container with VISIBLE imageButtons inside. When an image from the bottom container is clicked it should be put in the top left of the top container and the images below should change allowing the user to select a new image (screenshot1-screenshot2). When one of these new images is selected, it should join the previous image in the top container next to the last clicked image, and again the images in the bottom container should change allowing the user to select another image (screenshot2-screenshot3) which should again join the top container and have the bottom container change its images. What i have so far achieves this but only on one set path little hard to explain so let me add some screen shots to demonstrate
when the app starts you should be able to select any of these 3 image buttons the selection should go to the top left and switch images at the bottom according to which was clicked
when imageButton1 is clicked
when imageButton3 is clicked
when imageButton2 is clicked
now this appears to be correct but after imageButton1 is clicked if you were to select imageButton2 instead of imageButton3 (the image that looks like its eating, dont worry im actually very good at drawing and will be changing all these images,) the last screenshot is displayed and on the third screen shot if you were to select the cola bottle (imageButton1) it jumps back to screenshot 2 but with imageButton3 still displayed in the top container like this
now i know that this is because i have told it to do this in my .java file the problem is im not sure how to rectify this as android provides static id's for each button i think it may be a case of writing an extra conditional before my "speak=" statement but as i have stated im fairly new to all this and for the time being am a little stumped can anybody help me? here is my code
package com.martinsapp.socialstories;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.os.Bundle;
import android.widget.ImageButton;
public class speakActivity extends Activity{
int speak = 1;
ImageButton btn1;
ImageButton btn2;
ImageButton btn3;
ImageButton btn4;
ImageButton btn5;
ImageButton btn6;
ImageButton btnmt1;
ImageButton btnmt2;
ImageButton btnmt3;
ImageButton btnmt4;
ImageButton btnmt5;
ImageButton btnmt6;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_speak);
btn1 = (ImageButton)findViewById(R.id.imageButton);
btn1.setOnClickListener(ButtonClickListener);
btn1.setBackgroundColor(View.INVISIBLE);
btn2 = (ImageButton)findViewById(R.id.imageButton2);
btn2.setOnClickListener(ButtonClickListener);
btn2.setBackgroundColor(View.INVISIBLE);
btn3 = (ImageButton)findViewById(R.id.imageButton3);
btn3.setOnClickListener(ButtonClickListener);
btn3.setBackgroundColor(View.INVISIBLE);
btn4 = (ImageButton)findViewById(R.id.imageButton4);
btn4.setOnClickListener(ButtonClickListener);
btn4.setBackgroundColor(View.INVISIBLE);
btn5 = (ImageButton)findViewById(R.id.imageButton5);
btn5.setOnClickListener(ButtonClickListener);
btn5.setBackgroundColor(View.INVISIBLE);
btn6 = (ImageButton)findViewById(R.id.imageButton6);
btn6.setOnClickListener(ButtonClickListener);
btn6.setBackgroundColor(View.INVISIBLE);
btnmt1 = (ImageButton)findViewById(R.id.imageButtonempty1);
btnmt1.setOnClickListener(ButtonClickListener);
btnmt1.setVisibility(View.INVISIBLE);
btnmt2 = (ImageButton)findViewById(R.id.imageButtonempty2);
btnmt2.setOnClickListener(ButtonClickListener);
btnmt2.setVisibility(View.INVISIBLE);
btnmt3 = (ImageButton)findViewById(R.id.imageButtonempty3);
btnmt3.setOnClickListener(ButtonClickListener);
btnmt3.setVisibility(View.INVISIBLE);
btnmt4 = (ImageButton)findViewById(R.id.imageButtonempty4);
btnmt4.setOnClickListener(ButtonClickListener);
btnmt4.setVisibility(View.INVISIBLE);
btnmt5 = (ImageButton)findViewById(R.id.imageButtonempty5);
btnmt5.setOnClickListener(ButtonClickListener);
btnmt5.setVisibility(View.INVISIBLE);
btnmt6 = (ImageButton)findViewById(R.id.imageButtonempty6);
btnmt6.setOnClickListener(ButtonClickListener);
btnmt6.setVisibility(View.INVISIBLE);
if (speak == 1){
btn1.setImageResource(R.drawable.i_want);
btn2.setImageResource(R.drawable.i_like);
btn3.setImageResource(R.drawable.i_feel);
btn4.setVisibility(View.INVISIBLE);
btn5.setVisibility(View.INVISIBLE);
btn6.setVisibility(View.INVISIBLE);
}
}
private View.OnClickListener ButtonClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
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);
btn4.setVisibility(View.VISIBLE);
btn5.setVisibility(View.INVISIBLE);
btn6.setVisibility(View.INVISIBLE);
btnmt1.setImageResource(R.drawable.i_want);
btnmt1.setVisibility(View.VISIBLE);
btnmt1.setBackgroundColor(View.INVISIBLE);
}
break;
case R.id.imageButton3:
speak = 3;
if (speak == 3){
btn1.setImageResource(R.drawable.fizz);
btn2.setImageResource(R.drawable.squash);
btn3.setImageResource(R.drawable.milkshake);
btn4.setVisibility(View.INVISIBLE);
btn5.setVisibility(View.INVISIBLE);
btn6.setVisibility(View.INVISIBLE);
btnmt2.setImageResource(R.drawable.a_drink);
btnmt2.setVisibility(View.VISIBLE);
btnmt2.setBackgroundColor(View.INVISIBLE);
}
break;
case R.id.imageButton2:
speak = 4;
if (speak == 4){
btn1.setImageResource(R.drawable.orange);
btn2.setImageResource(R.drawable.lemon);
btn3.setImageResource(R.drawable.apple);
btn4.setImageResource(R.drawable.blackcurrant);
btn5.setImageResource(R.drawable.strawberry);
btn3.setVisibility(View.VISIBLE);
btn4.setVisibility(View.VISIBLE);
btn5.setVisibility(View.VISIBLE);
btn6.setVisibility(View.INVISIBLE);
btnmt3.setImageResource(R.drawable.squash);
btnmt3.setVisibility(View.VISIBLE);
btnmt3.setBackgroundColor(View.INVISIBLE);
}
}
}
};
}