开发者

Android: cannot convert from String to Editable

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜