Q:

How to add items into listview on button click? 

In my application,there is a listview which contains some data. There is an edittext and a button in the same activity. When i type something in the edittext,i want to add that text as new item into ListView on a button click. How to do that?Please help...
Here is a sample of my code...
This is my customList adapter
public class MainActivity extends Activity 
{
    ListView list;

    String[] web = {
    "Google Plus",
        "Twitter",
        "Windows",
        "Bing",
        "Itunes",
        "Wordpress",
        "Drupal"
} ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       EditText et = (EditText)findViewById(R.id.editText1);
    Button b=(Button)findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener() {
         @Override
         public void onClick(View arg0) {
                  Toast.makeText(MainActivity.this, "Button clicked...", Toast. LENGTH_SHORT).show();
         }
    });

    CustomList adapter = new CustomList(MainActivity.this, web);
    list=(ListView)findViewById(R.id.list);
    list.setAdapter(adapter);
    list.setOnItemClickListener(new AdapterView. OnItemClickListener()  {
       @Override
       public void onItemClick(AdapterView<? > parent, View view,
                                            int position, long id) {
          Toast.makeText(MainActivity.this, "You Clicked at " +web[+ position], Toast. LENGTH_SHORT).show();

         }
     });

This is my adapter class
public class CustomList extends ArrayAdapter<String>{

private final Activity context;
private final String[] web;

public CustomList(Activity context,  String[] web) {
    super(context, R.layout.list_single, web);
    this.context = context;
    this.web = web;

}

@Override
public View getView(int position, View view, ViewGroup parent) {
   LayoutInflater inflater = context.getLayoutInflater();
   View rowView= inflater.inflate(R.layout.list_single, null, true);
   TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);

   txtTitle.setText(web[position]);

  return rowView;
}
}

A:

Declare 
final ArrayList<String> dataset = new ArrayList<String>();
Button b=(Button)findViewById(R.id.button1);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
final CustomList adapter = new CustomList(MainActivity.this, dataset, imageId);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) 
{
   dataset.add(et.getText().toString());
   adapter.notifyDataSetChanged();
}
});

Then
private  ArrayList<String>  web;
public CustomList(Activity context, ArrayList<String> web, Integer[] imageId) {
super(context, R.layout.list_single, web);

And in getView
txtTitle.setText(web.get(position));

Edit:
public class MainActivity extends Activity 
{
EditText ed;
CustomList adapter;
ArrayList<String> list = new ArrayList<String>();
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button b = (Button) this.findViewById(R.id.button1);
    ListView lv = (ListView) this.findViewById(R.id.listView1);
    ed= (EditText) this.findViewById(R.id.editText1);
    adapter = new CustomList(this,list);
    lv.setAdapter(adapter);
    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            list.add(ed.getText().toString());
            adapter.notifyDataSetChanged();
            }

    });

}
}

activity_main.xml;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="16dp"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Button" />

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/button1"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editText1" >
    </ListView>

</RelativeLayout>

CustomList
public class CustomList extends ArrayAdapter<String>{

private  ArrayList<String >web;
LayoutInflater mInflater;
public CustomList(Context context, ArrayList<String> web) {
    super(context, 0, web);
    mInflater= LayoutInflater.from(context);
    this.web = web;

}
@Override
public View getView(int position, View view, ViewGroup parent) {

   View rowView= mInflater.inflate(R.layout.list_item,parent,false);
   TextView txtTitle = (TextView) rowView.findViewById(R.id.textView1);
   txtTitle.setText(web.get(position));
  return rowView;
}
}

list_item
<? xml version="1.0" encoding="utf-8"? >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="26dp"
        android:text="TextView" />

</RelativeLayout>

Snap

