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
if you used List object and passed to the adapter you can remove the value from the List object and than call the notifyDataSetChanged() using adapter object.
for e.g.
List<String> list = new ArrayList<String>();
ArrayAdapter adapter;
adapter = new ArrayAdapter<String>(DeleteManyTask.this,
android.R.layout.simple_list_item_1,
(String[])list.toArray(new String[0]));
listview = (ListView) findViewById(R.id.list);
listview.setAdapter(adapter);
listview.setAdapter(listAdapter);
for remove do this way
list.remove(index); //or
list.clear();
adpater.notifyDataSetChanged();
or without list object remove item from list.
adapter.clear();
adpater.notifyDataSetChanged();
You can only use
lv.setAdapter(null);
I used this statement and it worked for me:
setListAdapter(null)
This one calls a default constructor that does nothing in a class extends BaseAdapter.
use any one of the bellow options which suites your requirement
listview.removeViews(1,listview.getChildCount());
or
listview.removeViewInLayout(your view);
An other approach after trying the solutions below. When you need it clear, just initialise your list to new clear new list.
List<ModelData> dataLists = new ArrayList<>();
RaporAdapter adapter = new RaporAdapter(AyrintiliRapor.this, dataLists);
listview.setAdapter(adapter);
Or set visibility to Gone / Invisible up to need
img_pdf.setVisibility(View.INVISIBLE);