Q:

Why does my Android ListAdapter only show one item?

In my Android app I'm trying to build my very first custom listadapter. I now managed to get it to display one item, but unfortunately one item only where there are 8 in the list. My adapter looks like this:
public class PossibilitiesAdapter extends BaseAdapter {
    private AdapterCallbacks callbacks;
    private List<String> possibilitiesList = new ArrayList<String>();
    private LayoutInflater inflater;

    public PossibilitiesAdapter(Context context) {
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public void setPossibilitiesList(List<String> possibilitiesList) {
        for (String possibility : possibilitiesList) {
            addItem(possibility);
        }
    }

    public void addItem (final String item) {
        possibilitiesList.add(item);
        notifyDataSetChanged();
    }

    private class ViewHolder {
        TextView possibilityTitle;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.list_item_posibility, viewGroup, false);
        holder.possibilityTitle = (TextView) convertView.findViewById(R.id.text_possibility);
        holder.possibilityTitle.setText(possibilitiesList.get(position));

        return convertView;
    }

    @Override
    public int getCount() {
        return possibilitiesList.size();
    }
    // And here are some more things like getItemId() and getItem()
}

and I set the possibilitiesList from my fragment like so:
List<String> list = Arrays.asList(getResources().getStringArray(R.array.the_possibilities));
Log.e(this, new Integer(list.size()).toString()); // Outputs 8, so there are enough in the array.
adapter.setPossibilitiesList(list);

My fragment_possibilities.xml looks like this:

<ListView
    android:id="@+id/list_possibilities"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

and my list_item_possibility.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/text_possibility"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

So the problem is that it only displays the first item, and nothing more. Does anybody know what the problem is and how I can fix it?

A:

Are you nesting your list inside a ScrollView? It would be a typically behaving that it only shows one item. Try to avoid it o use the following method.
/**
 * read all adapter views and calculate total length
 *
 * @param listView
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;
    }

    int totalHeight = 0;
    int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.AT_MOST);
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
        totalHeight += listItem.getMeasuredHeight();
    }

    setListViewHeight(listView, totalHeight);
}

/**
 * set listview height
 *
 * @param listView
 * @param height
 */
public static void setListViewHeight(ListView listView, int height) {
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = height + (listView.getDividerHeight() * (listView.getAdapter().getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}

No that will not work, as I said, you cant put a ListView Inside a ScrollView.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
    android:id="@+id/list_possibilities"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</LinearLayout>

