要实现GridView动态增加新的行,可以通过以下步骤实现:
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</GridView>
GridView gridView = findViewById(R.id.gridView);
ArrayList<String> dataList = new ArrayList<>();
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, dataList);
gridView.setAdapter(adapter);
notifyDataSetChanged()
方法来更新GridView的内容:dataList.add("New Row");
adapter.notifyDataSetChanged();
这样就可以实现动态增加新的行了。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:GridView同时进行多行的编辑,可动态增加新的行