3

私は初心者で、事前定義された配列に項目を追加したい

public class MainActivity extends ListActivity {
        //LIST OF ARRAY STRINGS WHICH WILL SERVE AS LIST ITEMS
        ;
        String listItem[]={"Dell Inspiron", "HTC One X", "HTC Wildfire S", "HTC Sense", "HTC Sensation XE"};


        ArrayAdapter<String> adapter;
        EditText et;

        @Override
        public void onCreate(Bundle icicle) {

        super.onCreate(icicle);
        setContentView(R.layout.main);
        adapter=new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1,
            listItem);
        setListAdapter(adapter);
        et=(EditText) findViewById(R.id.editText);
    }


    public void addItems(View v) {
        String data=et.getText().toString();
        listItem.add(""+data);
        adapter.notifyDataSetChanged();
    }
}
4

1 に答える 1