Example usage for android.widget ArrayAdapter getView

List of usage examples for android.widget ArrayAdapter getView

Introduction

In this page you can find the example usage for android.widget ArrayAdapter getView.

Prototype

@Override
    public @NonNull View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) 

Source Link

Usage

From source file:nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapterv2.java

public void justifyListViewHeightBasedOnChildren(ListView listView) {
    ArrayAdapter adapter = (ArrayAdapter) listView.getAdapter();

    if (adapter == null) {
        return;/* w  w  w .ja v a  2  s.c o  m*/
    }
    ViewGroup vg = listView;
    int totalHeight = 0;
    for (int i = 0; i < adapter.getCount(); i++) {
        View listItem = adapter.getView(i, null, vg);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams par = listView.getLayoutParams();
    par.height = totalHeight + (listView.getDividerHeight() * (adapter.getCount() - 1));
    listView.setLayoutParams(par);
    listView.requestLayout();
}