Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>MainActivity.java</strong></p> <pre><code>public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final EditText et = (EditText) findViewById(R.id.et); EditText et1 = (EditText) findViewById(R.id.et1); Button button = (Button) findViewById(R.id.button1); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub final Map&lt;String, String&gt; demomap = new HashMap&lt;String, String&gt;(); demomap.put(et.getText().toString(), et.getText().toString()); SharedPreferences preferences = getSharedPreferences("sample", 0); SharedPreferences.Editor editor = preferences.edit(); for (Entry&lt;String, String&gt; entry : demomap.entrySet()) { editor.putString(entry.getKey(), entry.getValue()); } editor.commit(); Intent intent = new Intent(MainActivity.this, secondactvity.class); startActivity(intent); } }); } } </code></pre> <p><strong>secondActivity.java</strong></p> <pre><code>public class secondactvity extends Activity { private HashMap&lt;String, String&gt; demomap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button back = (Button) findViewById(R.id.button2); demomap = new HashMap&lt;String, String&gt;(); SharedPreferences preferences = getSharedPreferences("sample", 0); for (Entry&lt;String, ?&gt; entry : preferences.getAll().entrySet()) { demomap.put(entry.getKey(), entry.getValue().toString()); } LinearLayout layout = (LinearLayout) findViewById(R.id.linear); Iterator myVeryOwnIterator = demomap.keySet().iterator(); while (myVeryOwnIterator.hasNext()) { String key = (String) myVeryOwnIterator.next(); String value = (String) demomap.get(key); Button button = new Button(this); button.setText(value); layout.addView(button); } back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); } } </code></pre> <p>Now i hope its problem is solved.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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