2011-03-17 214 views
2

嗨我的應用程序出現問題。當我爲Android 2.2或更低版本創建一個新項目時,我的應用程序正常工作,我的麪包在屏幕上顯示,但是當我使用相同的代碼爲2.3或2.3.3創建新項目時,烤麪包根本不會出現。此外,我已經在主OnCreate線程中添加了Textview更新,但仍然沒有更新textview。我需要主要解決吐司問題。 謝謝Android 2.3.3上的Toast Widget

public class Location extends Activity { 
/** Called when the activity is first created. */ 
static String Text; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 


    LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    final TextView tv = (TextView)findViewById(R.id.textView1); 

    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() { 



    private final String TAG = null; 

    @Override 
    public void onLocationChanged(android.location.Location location) { 
     // TODO Auto-generated method stub 

     Text = "My current location is: " + "Latitud = " + location.getLatitude() + "Longitud = " + location.getLongitude(); 
     Context context = getApplicationContext(); 
     int duration = Toast.LENGTH_SHORT; 
     Toast.makeText(context, Text, duration).show(); 
      tv.setText(Text); 
     try 
     { 
      File root = Environment.getExternalStorageDirectory(); 
      File gps = new File(root, "log.txt"); 




     BufferedWriter out = new BufferedWriter(
       new FileWriter(gps,true)) ; 

     out.write(Text); 
     out.write(""); 
     out.close(); 

     } 


     catch (IOException e) { 


      Log.e(TAG, "Could not write file " + e.getMessage()); 

     } 
    } 
+0

我編輯的代碼包括.show烤麪包,但沒有區別。 – Nekro 2011-03-17 18:21:45

回答

3

你必須在吐司上調用show()。

Toast.makeText(context, Text, duration).show(); 

所有你正在做的是創建吐司,而不是顯示它。

TextView更新可能因爲異常而失敗。

+0

哦,上帝哈哈我添加了.show(必須在複製和粘貼時刪除),但仍然不顯示。什麼樣的異常可能導致textview不更新。 – Nekro 2011-03-17 17:28:45

+0

您正在嘗試寫出文件的try塊中更新TextView。 – 2011-03-17 17:32:39

+0

我移動了IO異常塊後的TextView更新,它仍然沒有更新,我的麪包仍然不顯示。由於吐司在2.2或更低的情況下正常工作,它令我瘋狂。 – Nekro 2011-03-17 17:51:18