0

这是我的问题:我有一个具有 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,但是当我编辑这些字段并且我回到我的主要活动时(位置之一是左侧的位置)我的页面适配器,这个在中间,最后一个是正确的)我有一个按钮可以将我的活动中的所有数据保存到我的 SQLite 数据库中......一切正常,但是当我修改地址的 edditText 字段时从地址位置自动填充一些 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("...") 我们就不能再修改它了?

4

2 回答 2

1

验证:您似乎暗示您的字符串“display”正在显示旧数据。是这样吗?

当您想从 EditTexts 中获取文本时,您是否在 PagerAdapter 的正确页面中查找那些 findViewById()s?

你在使用 FragmentPagerAdapter 吗?如果您的寻呼机页面是片段,您可能需要在它们之间传递信息,因为它们的生命周期发生变化。

于 2012-04-02T21:55:10.607 回答
0

是的,确实,我的字符串显示正在显示旧数据,

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

于 2012-04-03T14:53:17.027 回答