这是我的问题:我有一个带有3个视图的页面适配器,左边的一个用来本地化用户,并用本地化的地址的不同元素填充一些editText字段,方法如下:
private boolean getAddressLocation(Location location) {
if (location != null) {
lat = location.getLatitude();
longi = location.getLongitude();
Geocoder gc = new Geocoder(NoteReminder.this, Locale.getDefault());
try {
List<Address> addresses = gc.getFromLocation(lat, longi, 1);
if (addresses.size() > 0) {
Address address = (Address) addresses.get(0);
streetNumber = address.getAddressLine(0);
locality = address.getLocality();
postcode = address.getPostalCode();
country = address.getCountryName();
etCountry.setText(country, TextView.BufferType.EDITABLE);
etPostcode.setText(postcode, TextView.BufferType.EDITABLE);
etLocality.setText(locality, TextView.BufferType.EDITABLE);
etAddressText.setText(streetNumber, TextView.BufferType.EDITABLE);
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}问题是,如果本地化不够精确,我希望用户能够编辑editText,但当我编辑这些字段时,我返回到我的主要活动(位置1是在我的页面适配器的左侧,这个位置在中间,最后一个是右侧),我有一个按钮将所有来自我的活动的数据保存到我的SQLite数据库中...一切正常,但当我修改地址的eedditText字段时,这些字段是由地址位置的一些setText自动填充的,存储在我的数据库中的值仍然是自动填充我的editText的字段……
...
etCountry = (EditText) findViewById(R.id.etCountry);
etPostcode = (EditText) findViewById(R.id.etPostcode);
etLocality = (EditText) findViewById(R.id.etLocality);
etAddressText = (EditText) findViewById(R.id.etAddressText);
display = etAddressText.getText() + "," + etLocality.getText() + "," + etPostcode.getText()
+ "," + etCountry.getText();
...我不明白?这是否意味着一旦editText中填充了一个.setText("...")我们不能再修改它了?
发布于 2012-04-03 05:55:11
验证:您似乎是在暗示您的字符串"display“显示的是旧数据。真的是这样吗?
当您想从PagerAdapter中获取文本时,是否在findViewById()的正确页面中查找这些EditTexts ()?
你在用FragmentPagerAdapter吗?如果您的寻呼机页面是片段,则可能需要在它们的生命周期发生变化时在它们之间传递信息。
发布于 2012-04-03 22:53:17
是的,确实,我的字符串显示显示的是旧数据,
Are you looking in the correct page of your PagerAdapter for those findViewById()s when you want to get the text out of the EditTexts?==>我只是做了一个简单的
etCountry = (EditText) findViewById(R.id.etCountry);
etPostcode = (EditText) findViewById(R.id.etPostcode);
etLocality = (EditText) findViewById(R.id.etLocality);
etAddressText = (EditText) findViewById(R.id.etAddressText);从我的pageAdapter的另一个页面
在做"getText“之前,我使用的不是fragmentPageAdapter,而是一个简单的pageAdapter。
https://stackoverflow.com/questions/9984120
复制相似问题