1

Well my question is rather simple

In my layout I have a EditText and two ImageView

I type in any word EditText in two ImageView that I have to be to display images according to the letter, send it as the word of EditText call my problem arises when you want to call one letter for example:

if I enter the word "home" should go in the word and show the two ImageView image according to the letter then would show C (image C) then A (Picture A)

the problem is that I can make the process of finding one letter, I've tried with a for but only recognizes the last letter, I also tried to make a kind of delay (delay) but did not work

part of my code:

public class deletreo extends Activity {

    protected TextView tv;
    protected EditText etxt;
    protected ImageView img,img2;

    final Handler handle = new Handler();

    protected void mth(){
        Thread t = new Thread(){
            public void run(){

                try{
                    Thread.sleep(1000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }
                handle.post(proceso);
            }
        };
        t.start();
    }

    final Runnable proceso = new Runnable(){
        public void run(){
            letra();
        }
    };


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        tv = new TextView(this);
        setContentView(R.layout.deletreo);


        etxt = (EditText)findViewById(R.id.text);
        Button btn = (Button)findViewById(R.id.btn7);

        btn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                mth();

            }   
        });



    }//fin bundle





     private void letra()  {

        String t = etxt.getText().toString();

            char[] array = t.toCharArray();
            int p = array.length;

                for(int j=0; j<p;j++){

                    if(array[j] == 'a' || array[j] == 'A'){
                        img = (ImageView)findViewById(R.id.img);
                        img.setImageResource(R.drawable.aa);
                        img2 = (ImageView)findViewById(R.id.img2);
                        img2.setImageResource(R.drawable.image_1);
                        onStop();
                    }

                        if(array[j] == 'b' || array[j] == 'B'){
                            img = (ImageView)findViewById(R.id.img);
                            img.setImageResource(R.drawable.bb);
                            img2 = (ImageView)findViewById(R.id.img2);
                            img2.setImageResource(R.drawable.image_2);

                        }

any idea how to solve this problem?

Miral Dhokiya
  • 1,720
  • 13
  • 26
DiegoF
  • 84
  • 9
  • 1
    i don't understand the problem, but it doesn't seem logical that you are using the same imageview for all letters in the word – njzk2 Dec 26 '12 at 09:02
  • for me a little logic, what I intend to do is show a picture and letter in the array go letter by letter – DiegoF Dec 26 '12 at 10:03
  • but for each letter, you'll put the image in the same image view, hence displaying only the last letter – njzk2 Dec 26 '12 at 10:13
  • if on the same ImageView, and for that very reason I wanted to use the delay, in order to show one letter – DiegoF Dec 26 '12 at 10:44
  • then the issue is that your loop is in the wrong place. your delay is applied once, before you display anything. – njzk2 Dec 26 '12 at 11:36
  • yeah, that's what he does, does all the process and end for me shows the last letter of the word – DiegoF Dec 26 '12 at 11:38

1 Answers1

1

the problem is that I can make the process of finding one letter, I've tried with a for but only recognizes the last letter, I also tried to make a kind of delay (delay) but did not work

Of course, it behaves that way. Because you are putting delay for 1 second in starting and after that you are calling method letra() which sets image resource in both imageviews in a loop. So you can see only images associated with last letter.

Try it this way instead:

public class deletreo extends Activity {

    protected TextView tv;
    protected EditText etxt;
    protected ImageView img,img2;

    final Handler handle = new Handler();

    protected void mth(){
        Thread t = new Thread(){
            public void run(){

                try{
                    Thread.sleep(1000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }

            }
        };
        t.start();
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        tv = new TextView(this);
        setContentView(R.layout.deletreo);


        etxt = (EditText)findViewById(R.id.text);
        Button btn = (Button)findViewById(R.id.btn7);

        btn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                letra();

            }   
        });



    }//fin bundle

     private void letra()  {

        String t = etxt.getText().toString();

            char[] array = t.toCharArray();
            int p = array.length;

            for(int j=0; j<p;j++){

            if(array[j] == 'a' || array[j] == 'A'){
                img = (ImageView)findViewById(R.id.img);
                img.setImageResource(R.drawable.aa);
                img2 = (ImageView)findViewById(R.id.img2);
                img2.setImageResource(R.drawable.image_1);
                onStop();
                    }

            if(array[j] == 'b' || array[j] == 'B'){
                img = (ImageView)findViewById(R.id.img);
                img.setImageResource(R.drawable.bb);
                img2 = (ImageView)findViewById(R.id.img2);
                img2.setImageResource(R.drawable.image_2);

            }
            mth();
        }
    }
}

Call delay function mth() after each round of loop. Hope it works.

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
  • Thanks for your answer, but it has not worked, I've tried before and for some reason it does not work. the problem is that it does not delay when the array runs and should run one letter – DiegoF Dec 26 '12 at 10:01
  • @DiegoF, Try giving delay of more than 1 second. May be its so fast, you can not notice – MysticMagicϡ Dec 26 '12 at 10:08
  • no, still does not work, performed first 3 sec delay and then shows me the last letter of the word – DiegoF Dec 26 '12 at 10:49