2013-02-11 30 views
0

在我的情況下,我在當前活動中設置了編輯文本和按鈕,然後例如我在編輯文本中輸入了「hey」 *這裏是我當前的代碼當前活動如何在不同的文本視圖中獲取在edittext中輸入的每個字母的顯示

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

然後在接下來的活動,我把3 TextView的,我做這部分,但它只能顯示所有我輸入一個TextView的 ,而不是單獨 *這裏是我的下一個當前代碼活動

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

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

現在我想發生什麼事是,每個字母將被顯示在不同的TextView

...任何建議將被罰款,以提高我的應用程序

+0

我強烈建議不要使用字符串對象的變量的名稱字符串。 – Dayerman 2013-02-11 00:21:25

+0

你能解釋一下你想做什麼嗎?你想在Activity 1的editText中編寫「hey」,以及你想在下一個Activity的文本框中出現什麼? – Dayerman 2013-02-11 00:24:51

+0

我在下一個活動中放置了3個textfield或textviews,每個嘿的字母將分配給3textfield或textview,例如:h在textview1中,e在textview2中,y在textview3中; – 2013-02-11 00:28:01

回答

0

一旦你在接下來的活動中的字符串變量。要獲取這些字符並在3個文本字段之間進行劃分,例如here,您可以看到如何將字符串拆分爲等份。然後你只需要在每個編輯文本中放置該子字符串。

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+"})"); 
} 
+0

哦...所以拆分數組是關鍵...我會試着在那個代碼上做實驗,但是我可以問一下:private static String [] splitArray(String str2split,int letters){ return str2split。 split(「(?<= \\ G。{」+ letters +「})」); }' 代碼幹什麼?特別是在第二行... – 2013-02-11 01:58:07

+0

你可以在這裏看到的解釋http://stackoverflow.com/questions/3760152/split-string-to-equal-length-substrings-in-java – Dayerman 2013-02-11 15:22:31

相關問題