List activity with header, footer and empty all visible

前端 未结 8 1334
失恋的感觉
失恋的感觉 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:45

    This answer is a bit late, but you can simply override BaseAdapter.isEmpty() to return false.

    public boolean isEmpty() {
        return false;
    }
    
    0 讨论(0)
  • I found that header/footer will always be visible if you don't call ListView.setEmptyView.

    Instead, manually show/hide your empty view:

    emptyView.setVisibility(list.size() == 0 ? View.VISIBLE : View.GONE);
    
    0 讨论(0)
  • 2021-01-08 00:51

    You could use my MergeAdapter for this. Add the header view, add the data adapter, and add the footer view. They will all scroll in unison, and the header and footer will persist even if the adapter in the middle has no rows.

    0 讨论(0)
  • 2021-01-08 00:51

    I meet the same issue, if ListView has no item, you could ListView.setAdapter(new SomeAdapter(new ArrayList())); and the header is also visible.

    0 讨论(0)
  • 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 {
    ...
    }
    
    0 讨论(0)
  • 2021-01-08 01:01

    Make your empty view include your header.

    i.e.

     <ListView />
     <RelativeLayout
        android:id="@android:id/empty"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
           // Add whatever you want here including your header
     </RelativeLayout>
    
    0 讨论(0)
提交回复
热议问题