How to remove listview all items

后端 未结 11 2129
野的像风
野的像风 2020-12-15 15:36

In my app, if you click on a button then i want to remove all the listview items. Here, i am using the base adapter for adding the items to the list view.

How can i

11条回答
  •  自闭症患者
    2020-12-15 16:24

    For me worked this way:

    private ListView yourListViewName;
    private List yourListName;
    
      ...
    
    yourListName = new ArrayList<>();
    yourAdapterName = new yourAdapterName(this, R.layout.your_layout_name, yourListName);
    
      ...
    
    if (yourAdapterName.getCount() > 0) {
       yourAdapterName.clear();
       yourAdapterName.notifyDataSetChanged();
    }
    
    yourAdapterName.add(new YourClassName(yourParameter1, yourParameter2, ...));
    yourListViewName.setAdapter(yourAdapterName);
    

提交回复
热议问题