0

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

app starts

when imageButton1 is clicked

imageButton1 Clicked

when imageButton3 is clicked

imageButton3 Clicked

when imageButton2 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

wrong wrong wrong

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);

                }
                }


}
};
}
martinseal1987
  • 1,862
  • 8
  • 44
  • 77
  • Your question is very hard to understand. Sorry I've read it now about 3 times and I still don't understand it. But I would give you the advise to create your `Buttons` dynamically (e.g.: http://stackoverflow.com/questions/1851633/how-to-add-button-dynamically-in-android). – owe Feb 03 '14 at 15:37
  • @owe I appreciate that what is it that makes it impossible to understand from your point of view so I can edit or ellaborate – martinseal1987 Feb 03 '14 at 15:56
  • Take a look at [this](http://stackoverflow.com/help/mcve). – takendarkk Feb 03 '14 at 16:13
  • @Takendarkk I have looked at this before posting and have tried not to add to much code at the same time as making sure ppl can reproduce it – martinseal1987 Feb 03 '14 at 16:20
  • Side Note: I see `speak = 2; if (speak == 2){ ... }` You don't need the comparison considering the previous line ensures it will return true. – takendarkk Feb 03 '14 at 16:29
  • What I want is if you click imageButton2 from the first screenshot do this ......... If you click imageButton2 from the second screenshot do something else....... – martinseal1987 Feb 03 '14 at 16:35

0 Answers0