2011-04-11 71 views
1

我是新來的機器人。我剛剛使用Aynctask創建了一個簡單的應用程序。基本上,它使用Asynctask來遍歷一個循環,並在文本框中顯示迭代編號。我創建了一個edittext和一個textview,bot展示了一些奇怪的文本。我嘗試創建敬酒,而敬酒正確顯示相同的文字。這裏是源代碼:Android編輯文本顯示奇怪的文字

package com.jeannius.me; 

import android.app.Activity; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.os.SystemClock; 
import android.text.InputType; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 
import android.widget.Toast; 

public class Main extends Activity { 
    /** Called when the activity is first created. */ 
    int[] color1 = {0xFFe48701, 0xFFa5bc4e, 0xFF1b95d9, 0xFFcaca9e, 0xFF6693b0, 0xFFf05e27, 0xFF86d1e4, 
      0xFFe4f9a0, 0xFFffd512, 0xFF75b000, 0xFF0662b0, 0xFFede8c6, 0xFFcc3300, 0xFFd1dfe7, 
      0xFF52d4ca, 0xFFc5e05d, 0xFFe7c174, 0xFFfff797, 0xFFc5f68f, 0xFFbdf1e6, 0xFF9e987d, 
      0xFFeb988d, 0xFF91c9e5, 0xFF93dc4a, 0xFFffb900, 0xFF9ebbcd, 0xFF009797, 0xFF0db2c2}; 

    TextView yyr; 
    EditText ud; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     yyr = (TextView)findViewById(R.id.mytext); 
     ud = (EditText)findViewById(R.id.edit); 




     Button myb =(Button)findViewById(R.id.mybut); 
     yyr.setTextColor(0xFFE48701); 
     ud.setRawInputType(InputType.TYPE_CLASS_TEXT); 

     myb.setOnClickListener(new View.OnClickListener() { 


      public void onClick(View v) { 

       new mySyncTask().execute();    
      } 

     });  

    } 

    class mySyncTask extends AsyncTask< Void, Integer, Void>{ 

     String red;  

     @Override 
     protected Void doInBackground(Void... unused) { 

      for(Integer j=0; j<5; j++){    
       red = String.valueOf(j);     
       publishProgress(j);    
      SystemClock.sleep(3000);}   
      return null; 
     } 


     @Override 
     protected void onPostExecute(Void result) { 
      Toast.makeText(getApplicationContext(), red.toString(), Toast.LENGTH_LONG).show(); 
     } 

     protected void onProgressUpdate(Integer... values) { 

      yyr.setText(String.valueOf(values)); 
      ud.setText(values.toString(), TextView.BufferType.EDITABLE); 
      Toast.makeText(getApplicationContext(), red.toString(), Toast.LENGTH_SHORT).show(); 

     }  

    } 

} 
+1

你在顯示的文本視圖中顯示紅色,爲什麼顯示值,爲什麼? – MByD 2011-04-11 22:34:54

+0

究竟是什麼「怪異」的文字? – 2011-04-11 22:44:35

回答

1

values是一個數組。像這樣使用它:String.valueOf(values[0])