简体   繁体   中英

TextView displays different text than received with getText

I have a problem with setText(). Although there were many questions about this issue, no single answer solved my problem..

I have one city name saved with SharedPreferences. I get city successfully from SharedPreferences. I want to do the following textview.setText(city) [of course, firstly I determine the textview with findbyId-proper, existing id ]. This is done in onResume() method. Than I use getText() and System.out.println(getText()) shows exactly the right, saved city. The UI shows the text which was defined at the XML layout of the activity. I have no idea what to do and how is this even possible. I do not get any errors. Please, help.

In onResume() method right after super.onResume(); :

        city=settings.getString("savedLocation", "null");
        textView.setText(city);
        System.out.println(city + " " textView.getText()); 

textView.getText() returns not text string, but object. You should use textView().getText().toString() to retrieve text from a text view

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM