Note that there are some explanatory texts on larger screens.

plurals
  1. POusing preferences -- my listview is empty (can't store data)
    primarykey
    data
    text
    <p>I need help in order to properly set up preferences.</p> <p>I have my main activity from which by pressing the menu button ,i am going to the preferences activity.There,i have 3 entries where the user inputs his data.The first entry is a serial number.</p> <p>I want to be able to show a list with all the serial numbers and when the user selects one,show him the other entries (or do some calculations ).</p> <p>----------UPDATED------------------------------------</p> <p>My main activity is:</p> <pre><code> public class Strength extends Activity implements OnClickListener{ View goto_list; SharedPreferences mypref; String [] values=new String [100]; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Set up click listeners goto_list=(View) findViewById(R.id.goto_list); goto_list.setOnClickListener(this); //Setup preferences mypref= PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor prefsEditr=mypref.edit(); final Integer counter =values.length; prefsEditr.putInt("size", counter); for (int i=0;i&lt;counter;i++) { prefsEditr.putString("serial_number"+i, values[i]); } prefsEditr.putString("date", ""); prefsEditr.putString("strength", "1.0"); prefsEditr.commit(); } </code></pre> <p>My goto_list activity which will show the listview with the serial numbers:</p> <pre><code> public class goto_list extends ListActivity { private final String TAG="list"; SharedPreferences mypref; String[] listItems = null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list); mypref= PreferenceManager.getDefaultSharedPreferences(this); final Integer counter = mypref.getInt("size",0); listItems=new String[counter]; for (int i=0;i&lt;counter;i++) { listItems[i] = mypref.getString("serial_number"+i, ""); } //what to do with ArrayAdapter? ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1,listItems); setListAdapter(adapter); } protected void onListItemClick(ListView l, View v, int position, long id) { Log.i(TAG, "position: " + position); Log.i(TAG, "item: " + listItems[position]); mypref.edit().putString("serial_number", listItems[position]).commit(); String item = (String) getListAdapter().getItem(position); Intent i=new Intent(this,calcs_strength.class); startActivity(i); finish(); } </code></pre> <p>So, my problem is that the listview is empty.It show no data.</p> <p>Thank you!</p>
    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.
 

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