Note that there are some explanatory texts on larger screens.

plurals
  1. POincrease button when value coming from sharedpreferences
    text
    copied!<p>I have editText in Activity. I used SharedPreference for saving this value and get later. I passed this edittext value to another activity button text. I need to increment button while text coming from edittext. But the problem is if i enter text, test then button is created with test text. If i create test1 then button test is replace with test1. I need to show test &amp; test1 with two buttons.</p> <p>code:</p> <p>Activity:</p> <pre><code>et=(EditText)findViewById(R.id.et); et1=(EditText)findViewById(R.id.et1); btn=(Button)findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { SharedPreferences preferences = getSharedPreferences("sample",0); SharedPreferences.Editor editor = preferences.edit(); editor.putString("Name",et.getText().toString()); editor.putString("Name1",et1.getText().toString()); editor.commit(); Intent intent = new Intent(Activity.this, Activity1.class); startActivity(intent); } }); </code></pre> <p>Activity1:</p> <pre><code>LinearLayout layout = (LinearLayout) findViewById(R.id.linear); SharedPreferences preferences = getSharedPreferences("sample",0); String Namestr=(preferences.getString("Name","")); String newString=""; if(Namestr.length()&gt;0&amp;&amp; Namestr.equalsIgnoreCase(newString)){ newString=Namestr; Button button = new Button(Get.this); // button.setText("hellow"); button.setText(preferences.getString("Name", "")); layout.addView(button); </code></pre> <p>xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_marginTop="0dp" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/linear" &gt; </code></pre> <p>It displays only one button. If i enter test it displays the button with test text, then i enter test2 it replace the test with test2. I don't want to replace text i need to create new button with test2.</p>
 

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