簡體   English   中英

AutocompleteTextView setText或setHint無法正常工作

[英]AutocompleteTextView setText or setHint not working

因此,在我的第一個活動中,我通過反向地理編碼將當前位置作為currentLocation,並且我使用sharedPreference將值傳遞給下一個活動( second.java/class )。 此類包含一個autocompleteTextView,其值存儲在數組中。

現在我想要的是,當用戶從第一個活動轉到第二個活動時,autocompleteTextView應該包含從第一個類獲得的位置作為提示Text

這是我的firstclass.java

Toast.makeText(this,currentPlace, 1000).show(); //works
SharedPreferences preferences = getSharedPreferences("myPrefss",  getApplicationContext().MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("CurrentPlace", currentPlace);
editor.commit();

和我的secondclass.java

SharedPreferences preferences = getSharedPreferences("myPrefss",  getApplicationContext().MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
String curlocation;
from = (AutoCompleteTextView) findViewById(R.id.et_login_form);
curlocation = editor.putString("CurrentPlace","");
from.setText(curlocation); //doesn't work
from.setHint(curlocation); //doesn't work

這是我的XML

        <AutoCompleteTextView
            android:id="@+id/et_login_form"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="5dp"
            android:inputType="textMultiLine"
            android:textColor="@android:color/black" />

而且我嘗試過通過xml設置文本

android:Text= "sample text"
android:Hint= "sample text"

它顯示在圖形視圖中,而不顯示在MobilePhone中

嘗試此操作,因為現在再次輸入shareprefrence嘗試從sharedpreference獲得價值。

curlocation = editor.getString("CurrentPlace","");

更換

curlocation = editor.putString("CurrentPlace","");

curlocation = editor.getString("CurrentPlace",null);

在XML文件中應該是。

android:text= "sample text"
android:hint= "sample text"

嘗試使用

curlocation = preferences.getString("CurrentPlace",""); 

代替

curlocation = editor.putString("CurrentPlace","");

編輯器僅用於sharedPreference中的商店值。 但是只為您獲取sharedPreference的用戶實例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM