嗨我的應用程序出現問題。當我爲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());
}
}
我編輯的代碼包括.show烤麪包,但沒有區別。 – Nekro 2011-03-17 18:21:45