2014-02-28 48 views
0

我的代碼可以標記輸入的字符串,但是當我輸入一個帶有空格的字符串時,它不能讀取空格。它只能讀取輸入的字...Android如何標記句子

希望你明白我想做

public class AlphabetCompareClass extends Activity { 
String get; 
ImageView img; 
int charIndex; 
char[] getArray; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.alphabetcompare); 
    Bundle gotWord = getIntent().getExtras(); 
    get = gotWord.getString("key"); 
    TextView Word = (TextView)findViewById(R.id.textView1); 
    img = (ImageView)findViewById(R.id.image_alpha); 
    Word.setText(get); 

    getArray = get.toCharArray(); 

    charIndex = 0; 
    Timer timer = new Timer(); 
    TimerTask timerTask = new ImageTimerTask(); 
    timer.schedule(timerTask, 0, 2000); 
}; 

public class ImageTimerTask extends TimerTask{ 
    ImageTimerTask imageTimerTask = this; 

    @Override 
    public void run() { 
      System.out.println("charIndex: " + charIndex); 
      System.out.println("this: " + getArray[charIndex]); 
      System.out.println("get length: " + get.length()); 

      runOnUiThread(new Runnable(){ 
       @Override 
       public void run() { 
        System.out.println("run UI thread!"); 
        InputStream is; 
        try { 
         is = getResources().getAssets().open(getArray[charIndex] + ".jpg"); 
         Bitmap bitmap = BitmapFactory.decodeStream(is); 
         img.setImageBitmap(bitmap); 
         charIndex++; 

         if(charIndex == get.length()){ 
          System.out.println("cancel!"); 
          imageTimerTask.cancel(); 
         } 
        } catch (IOException e) { 
         e.printStackTrace(); 
        } 
       } 
      }); 


    } 

} 

} 

回答

0

對於這種類型的任務的每個單獨的字符串我用字符串

的拆分方法

String[] tokens = longerString.split(" ");

+0

先生,我將如何將其應用於我的代碼? – kathleen55

+0

我回答了'如何標記句子'的問題。提供的代碼量很長,沒有註釋,並且不是特別清楚,所以我決定提供一個對許多人有用的答案,而不僅僅是修復你的代碼。 :) – Cheeseminer

+0

哦,先生,謝謝 – kathleen55