安卓学习笔记(二)用java增添和减少控件——安卓第二天

来源:互联网 发布:图片锐化软件 编辑:程序博客网 时间:2024/05/21 17:46
 addViewListBtn.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubListView list = new ListView(MainActivity.this);    ListViewMake listViewMake = new ListViewMake(1,list, MainActivity.this,    addListViewText1.getText().toString().trim(),addListViewText2.getText().toString().trim());    TableRow tableRow = new TableRow(MainActivity.this);    tableRow.addView(list);    bigTableLayout.addView(tableRow);}});                removeViewListBtn.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubint count = bigTableLayout.getChildCount();if (count - 9 > 0) {            bigTableLayout.removeViewAt(count - 1);}}});
就是这样用addView()和removeViewAt();
remove的时候先用getChildCount()看一下有几个儿子,比较安全
0 0
原创粉丝点击