Note that there are some explanatory texts on larger screens.

plurals
  1. POShared Preferences not found
    primarykey
    data
    text
    <p>Im trying to load SharedPreferences but the shared preferences never gets found, and im trying to update it from another class but that doesn't work as well. Im using a lst adapter for a list vieew as well. Any idea's for the following code? Im getting the back up hello string for the list view.</p> <pre><code>import android.app.ListActivity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class WorldMenu extends ListActivity{ SharedPreferences prefs = null; String splitter; String[] worldList; Context context; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); context = getBaseContext(); prefs = context.getSharedPreferences("worldString", 1); splitter = "Create World," + prefs.getString("worldString", "hello"); worldList = splitter.split(","); setListAdapter(new ArrayAdapter&lt;String&gt;(WorldMenu.this, android.R.layout.simple_list_item_1, worldList)); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); if(position == 0){ Intent openWorldNamer = new Intent("this works no need to check"); startActivity(openWorldNamer); } } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); finish(); } } </code></pre> <p>Edit Updater Class:</p> <pre><code>import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.View; import android.widget.Button; import android.widget.EditText; public class WorldCreator extends Activity{ EditText worldNameEditor; Button saver; SharedPreferences prefs; OnSharedPreferenceChangeListener listener; String updater2; Editor editor; String updater; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_worldcreator); prefs = PreferenceManager.getDefaultSharedPreferences(this); worldNameEditor = (EditText) findViewById(R.id.hello); saver = (Button) findViewById(R.id.button1); updater2 = worldNameEditor.getText().toString() + ","; saver.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub updater = updater2; editor = prefs.edit(); editor.putString("worldString", updater); editor.commit(); Intent openListWorld = new Intent("the list activity"); startActivity(openListWorld); }}); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload