ListView只显示一个元素

时间:2015-01-29 18:16:33

标签: android android-layout listview android-listview android-view

以下是我的布局活动布局

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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/transparent"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:paddingTop="5dp">
        // There are lots of views in here
    </FrameLayout>

    <include layout="@layout/story_entry_children_listview"/>
</LinearLayout>

以下是包含的布局

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">

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

</merge>

我的列表适配器是正确的,因为如果我在另一个活动布局的另一个ListView上应用,它会显示所有元素。可能在此活动布局中可能存在问题。请帮忙。

这是我的适配器类:

public class ChildEntryListAdapter extends BaseAdapter {

    private Context mContext;

    private ArrayList<StoryEntry> mListData;

    private LayoutInflater mLayoutInflater;

    public ChildEntryListAdapter(Context context, ArrayList<StoryEntry> listData) {
        mContext = context;
        mListData = listData;
        if(mListData == null) mListData = new ArrayList<>();
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mListData.size();
    }

    @Override
    public Object getItem(int i) {
        return mListData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        if (convertView == null) {
            convertView = (new StoryEntryChildView(mContext));
        }
        return convertView;
    }
}

0 个答案:

没有答案