0

これが私の問題です:私は3つのビューを持つpageadapterを持っています.左のものはユーザーをローカライズし、いくつかの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 を編集できるようにしたいということですが、これらのフィールドを編集するときにメインのアクティビティに戻ります (場所は の左側にありました)。私のpageadapter、これは真ん中にあり、最後のものは正しいものです)アクティビティからのすべてのデータを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("...") で満たされると、もう変更できないということですか?

4

2 に答える 2

1

確認するには:文字列「display」が古いデータを表示していることを暗示しているようです。そうですか?

EditTexts からテキストを取得するときに、これらの findViewById()s の PagerAdapter の正しいページを探していますか?

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);

マイページの別ページからAdapter

私の「getText」を実行する前に、fragmentPageAdapterではなく単純なpageAdapterを使用しています

于 2012-04-03T14:53:17.027 に答える