title: how to save data using shared preferences?
body: <p>i am new developer in android application.i have used shared preference concept to share the data from one activity to another activity.i have implemented code as follows</p>
  
  <p><strong>Main.java</strong></p>
  
  <pre><code>public class Main extends Activity 
  {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          TableLayout table=(TableLayout)findViewById(R.id.tableLayout1);
           table.removeAllViews();
          String sName = null;
          for(int i=0;i&lt;10;i++)
          {
              TableRow row=new TableRow(Main.this);
              row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
              TextView  name=new TextView(Main.this);
  
              name.setText(" HAI PRASAD"+i);
  
            sName=name.getText().toString();
  
              Log.v("sName 1111111","--&gt;"+sName);
  
               getSharedPreferences("Values", 0).edit().putString("NAMES",sName).commit();
  
  
              name.setGravity(Gravity.LEFT);
              name.setTypeface(Typeface.MONOSPACE);
  
                row.addView(name);
  
                table.addView(row);  
          }
  
          ((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
  
                  Intent it=new Intent(Main.this,Main2.class);
                  startActivity(it);
              }
          });
  
  
  }
  </code></pre>
  
  <p>here i am printing a name ten times and saving with shared preference as </p>
  
  <pre><code>TextView  name=new TextView(Main.this);
  
              name.setText(" HAI PRASAD"+i);
  
            sName=name.getText().toString();
  
              Log.v("sName 1111111","--&gt;"+sName);
  
               getSharedPreferences("Values", 0).edit().putString("NAMES",sName).commit();
  </code></pre>
  
  <p>here i would like to get the same data in Main2.class.the <strong>main2.java</strong> as follows</p>
  
  <pre><code>public class Main2 extends Activity 
  {
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
  super.onCreate(savedInstanceState);
  
      setContentView(R.layout.main2);
  
      String name=getSharedPreferences("Values", 0).getString("NAMES", "");
  
      ((TextView)findViewById(R.id.textView1)).setText(name);
  }
  </code></pre>
  
  <p>but here i am getting only one name that as HAI PRASAD9</p>
  
  <p>how can i get one by one </p>
  
  <blockquote>
    <p>HAI PRASAD0 HAI PRASAD1 HAI PRASAD2
    HAI PRASAD3 HAI PRASAD4 ......so on?</p>
  </blockquote>
  
  <p>please any one can help</p>
  
  <p>thanks in advance</p>