0

In my case, i set up edit text and a button in current activity, then for example i inputted "hey" in the edit text *here's my current code for the current activity

 text = (EditText)findViewById(R.id.editText1);
     compose = (Button)findViewById(R.id.button1);

     compose.setOnClickListener(new View.OnClickListener() {    

           //doneactivity button start
        @Override
        public void onClick(View arg0) 
        {       
        String string = text.getEditableText().toString();
        Intent intent= new Intent(Compose.this, DoneActivity.class);
        intent.putExtra("editText_value",string);
        startActivity(intent);  
            Compose.this.finish();
        }
    }); 

then in the next activity i put 3 textview, i'd done this part but it only display all i inputted in one textview and not separately *here's my current code for the next activity

TextView text = (TextView)findViewById(R.id.textView1);

    Intent i = getIntent();
    str = i.getStringExtra("editText_value");
    text.setText(str);

now what i want to happen is that per letter will be displayed in different textview

...any suggestion will be fine to improve my application

  • I would strongly recommend not to use the name string for the variable of the String object. – Dayerman Feb 11 '13 at 00:21
  • Could you explain a bit more what you want to do?You want to write in editText of Activity 1 "hey" and what exactly you want to appear in the textfields of next Activity? – Dayerman Feb 11 '13 at 00:24
  • i put 3 textfield or textviews in the next activity and each letter of hey will be distributed to the 3textfield or textview for example: h in textview1, e in textview2 and y in textview3; – Charles Casem Feb 11 '13 at 00:28

1 Answers1

0

Once you have the string variable in the next Activity. Is a matter of getting that characters and divide among the 3 textfields for example here you can see how to split an string in equals parts. Then you just need to put that substring in each edittext.

TextView textView1 = (TextView)findViewById(R.id.textView1);
TextView textView2 = (TextView)findViewById(R.id.textView2);
TextView textView3 = (TextView)findViewById(R.id.textView2);

textView1.setText(splitArray("hey", 1)[0]);
textView2.setText(splitArray("hey", 1)[1]);
textView3.setText(splitArray("hey", 1)[2]);

private static String[] splitArray(String str2split, int letters) {
    return str2split.split("(?<=\\G.{"+ letters+"})");
}
Community
  • 1
  • 1
Dayerman
  • 3,973
  • 6
  • 38
  • 54
  • oh... so split array is the key...i'll try and experiment on that code, but may i ask what does `private static String[] splitArray(String str2split, int letters) { return str2split.split("(?<=\\G.{"+ letters+"})"); }` code do? specially in the 2nd line... – Charles Casem Feb 11 '13 at 01:58
  • you can see here the explanation http://stackoverflow.com/questions/3760152/split-string-to-equal-length-substrings-in-java – Dayerman Feb 11 '13 at 15:22