title: adding ListView items with user input from AlertDialog
body: <p>im trying to fill a ListView with input from a AlertDialog which open an EditText in it. My problem is every time i give something in the AlertDialog with the EditText and click on my add button from the AlertDialog it fills all the 20 sets of my Array with the same String.But i want the he fill the String from the EditText only 1 time and i can work futher with this 1 item.</p>
  
  <p>here is my code</p>
  
  <p><b> MainActivity.java </b></p>
  
  <pre><code>public class MainActivity extends Activity {
  
      private static final int DIALOG_ALERT = 10;
  
      ListView list;
      Button addBtn;
      EditText input;
  
      String[] items;
      ArrayAdapter&lt;String&gt; adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          list = (ListView) findViewById(R.id.list);
          addBtn = (Button) findViewById(R.id.addPlanBtn);
  
          input = new EditText(this);
  
          items = new String[20];
  
          adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, items);
          list.setAdapter(adapter);
  
  
  
          addBtn.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
  
                  AlertDialog alert = new AlertDialog.Builder(MainActivity.this).create();
                  alert.setTitle("Train plan name");
                  alert.setMessage("enter a name:");
                  alert.setView(input);
  
  
  
  
                  alert.setButton("add", new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                              String value = input.getText().toString();
  
                              for(int i=0; i &lt; items.length; i++){     
                                  items[i] = value;
  
                              }
  
                       }
                    });
  
                      alert.show();
              }
  
  
          });
  
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  
  }
  </code></pre>
  
  <p><b> activity_main.xml </b></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity" &gt;
  
      &lt;ListView
          android:id="@+id/list"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_above="@+id/addPlanBtn"
           &gt;
  
      &lt;/ListView&gt;
  
      &lt;Button
          android:id="@+id/addPlanBtn"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentRight="true"
          android:text="add a new Plan" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Thank you for any help.</p>