List activity with header, footer and empty all visible

前端 未结 8 1325
失恋的感觉
失恋的感觉 2021-01-08 00:36

I would like to have the listview in a ListActivity be displayed with the header and footer visible all the time even if the list data is empty.

An empty list causes

8条回答
  •  清酒与你
    2021-01-08 00:57

    Ok, this workaround is a hack. But, without having to create a fake item.

    For an ArrayAdapter you can add a null item... i.e.

    myAdapter.add(null);
    

    And, in the MyAdapter getView(..) you do something like:

    myItem = getItem(position);
    if (myItem == null) {
       return getLayoutInflater().inflate(R.layout.my_empty_row, null);
    } else {
    ...
    }
    

提交回复
热议问题