I am new at Android and have a list to add and remove items at run time.
I am using the following code to add a new item:
public class MainActivity extends Activity {
private ListView list;
private Button btAdd;
private ArrayAdapter<String[]> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list=(ListView)this.findViewById(R.id.ListView1);
btAdd=(Button)this.findViewById(R.id.button1);
String [] name={"new Item"};
adapter=new ArrayAdapter<String[]>(this,R.id.ListView1);
adapter.add(name);
btAdd.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
list.setAdapter(adapter);
}
});
}
What is the problem with this?