Android:为什么这个代码不让我设置文本(浮动?)?
主要问题是eclipse希望我将getFloat更改为putFloat,然后当我这样做时,它希望我执行getInt,然后在float和Int之间循环。我只想将一个数字存储到textview字段中 因为coords是一个Android:为什么这个代码不让我设置文本(浮动?)?,android,floating-point,textview,sharedpreferences,Android,Floating Point,Textview,Sharedpreferences,主要问题是eclipse希望我将getFloat更改为putFloat,然后当我这样做时,它希望我执行getInt,然后在float和Int之间循环。我只想将一个数字存储到textview字段中 因为coords是一个共享参考文件,我想你不想在那里设置文本 你是说 LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = n
共享参考文件,我想你不想在那里设置文本
你是说
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(bestProvider);
SharedPreferences settings = getSharedPreferences("cars4sale",0);
SharedPreferences.Editor GPS = settings.edit();
GPS.putFloat("latitude", (float)location.getLatitude());
GPS.putFloat("longitude", (float)location.getLongitude());
GPS.commit();
TextView GPSTV = (TextView)findViewById(R.id.GPSTV);
SharedPreferences coords = getSharedPreferences("cars4sale",0);
String gpsstr = GPS.getFloat("gps", "");
GPSTV.setText(gpsstr);
这:
不起作用,因为GPS
是你的编辑器,而不是你的SharedReferences
。你需要这个
String gpsstr = GPS.getFloat("gps", "");
因为coords是一个共享参考文件
,我想你不想在那里设置文本
你是说
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(bestProvider);
SharedPreferences settings = getSharedPreferences("cars4sale",0);
SharedPreferences.Editor GPS = settings.edit();
GPS.putFloat("latitude", (float)location.getLatitude());
GPS.putFloat("longitude", (float)location.getLongitude());
GPS.commit();
TextView GPSTV = (TextView)findViewById(R.id.GPSTV);
SharedPreferences coords = getSharedPreferences("cars4sale",0);
String gpsstr = GPS.getFloat("gps", "");
GPSTV.setText(gpsstr);
这:
不起作用,因为GPS
是你的编辑器,而不是你的SharedReferences
。你需要这个
String gpsstr = GPS.getFloat("gps", "");
到底发生了什么事?您是否遇到异常,TextView是否为空,等等。似乎有很多代码无关紧要,您的布局有点古怪(我会清理一些),请提供一个真正的错误:什么时候发生了什么,谁不让您做什么,为什么?不过,我会在下面猜你的问题;)到底发生了什么事?您是否遇到异常,TextView是否为空,等等。似乎有很多代码无关紧要,您的布局有点古怪(我会清理一些),请提供一个真正的错误:什么时候发生了什么,谁不让您做什么,为什么?不过,我会在下面猜你的问题;)对接得好,对不起,打错了:)。但主要的问题仍然存在:它希望我将getFloat更改为putFloat,然后当我这样做时,它希望我执行getInt,然后在float和Int之间循环。不知道为什么,以前没有:)。。我来看看:)谢谢!我可以给你的全部功能,如果需要太多,它只是一个按钮。接得好,对不起,打错了:)。但主要的问题仍然存在:它希望我将getFloat更改为putFloat,然后当我这样做时,它希望我执行getInt,然后在float和Int之间循环。不知道为什么,以前没有:)。。我来看看:)谢谢!我可以给你的全部功能,如果需要太多,它只是一个按钮