Question

I'm trying to get a String from SavedPreferences and put it's contents into a Spanned class so it can be displayed in an EditText field using Html markup. I have pasted my current code below however I see why it doesn't work as a String and Spanned are not the same types...does anyone know of a good way around this?

public class SavedItemsActivity extends ItemsActivity {

private static SharedPreferences saveditems;

@Override
public Spanned getItem() {
    Spanned item = null;
    item = Html.fromHtml(saveditems.getString("CurrentSavedItem",""));
    return item;
}

I am unable to pass the string to the EditText directly. I tried using the below code (where 'itemtext' is the EditText):

ItemGenActivity.itemtext.setText(Html.fromHtml(saveditemss.getString("CurrentSavedItem",""));

The EditText is declared in the other ItemGenActivity as below:

public EditText itemtext
Was it helpful?

Solution

You cannot modify ItemGenActivity from another activity. ItemGenActivity can load the SharedPreferences and apply the value to its own EditText.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top