开发者

Android: cannot convert from String to Editable

开发者 https://www.devze.com 2023-02-26 04:20 出处:网络
A quick question: I am getting the error : cannot convert from String to Editable. Here is the code : Credential.getInstance().UserName = preferences.getString(\"UserName\", \"invalid value\");

A quick question:

I am getting the error : cannot convert from String to Editable. Here is the code :

Credential.getInstance().UserName = preferences.getString("UserName", "invalid value");
Credential.getInstance().Password = preferences.getString("UserName", "invalid value");

I've also tried casting like following:

Credential开发者_JS百科.getInstance().UserName = (Editable) preferences.getString("UserName", "invalid value");
Credential.getInstance().Password = (Editable) preferences.getString("UserName", "invalid value");

This time I am getting error : Cannot cast from String to Editable.

What to do?


For anyone interested in converting a String to Editable

Editable.Factory.getInstance().newEditable("myString");

From the docs, append is

Convenience for append(String.valueOf(text)).


Surely:

Credential.getInstance().UserName.append(preferences.getString("UserName", "invalid value"));

The API with the answers:

http://developer.android.com/reference/android/text/Editable.html

0

精彩评论

暂无评论...
验证码 换一张
取 消