如何添加项ListView控件在运行时控件、ListView

2023-09-07 02:33:45 作者:酒巷清风

我想知道如何将一个新的文本视图添加到Android中出现的ListView ,(例如,当我点击一些按钮,一个新的列表项添加到列表视图)?

I want to know how to add a new text view to appearing ListView in android, ( for example. when I click on some button a new list item is added to the list view )?

推荐答案

您只需将对象添加到包含的列表视图显示的对象的容器。那你告诉ListView控件适配器的变化已经发生:

You simply add the object to the container that contains the objects displayed by the listview. Then you tell the listView adapter that a change has occured:

public void onClick(View v) {
list.add(someObject);
((ArrayAdapter<Object>) listView.getAdapter()).notifyDataSetChanged();
setContentView(R.layout.list_view);