嗨,我的应用程序有问题。当我为 Android 2.2 或更低版本创建一个新项目时,我的应用程序运行良好,并且我的 toast 显示在屏幕上,但是当我使用相同的代码为 2.3 或 2.3.3 创建一个新项目时,toast 根本不会出现。我还在主 OnCreate 线程中添加了 Textview 更新,但我的 textview 仍然没有更新。我主要需要解决吐司问题。谢谢
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());
}
}