Android ListView: How to add a row with a buttonclick

Viewed 2032

I have a listview. In it, each row had a text saying 0:00. But now, I added a button on my actionbar but then I got stuck. I don't know how to make the button create a new row, displaying 0:00

This is my code for the data in a row.

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    RowData rowdata_data[] = new RowData[]
            {                   
             new RowData("0:00")            
            };

    RowdataAdapter adapter = new RowdataAdapter(this, 
            R.layout.listview_item_row, rowdata_data);
    listView1.setAdapter(adapter);

    listView1 = (ListView)findViewById(R.id.listView1);
}

this is my RowData class:

public class RowData {
String title;

public RowData(String title) {                     
    this.title = title;
}
}

So how should I implement a button click to add another row? Under addtionbutton: should be the method.

public boolean onOptionsItemSelected(MenuItem item) 
{

    // Handle presses on the action bar items
    switch (item.getItemId()) 
    {
        case R.id.additionbutton:                      

            return true;           
        default:
            return super.onOptionsItemSelected(item);
    }
}
2 Answers
Related