Java ArrayAdapter';s getView()提供了不支持的操作异常:AdapterView中不支持addView(视图,布局参数)

Java ArrayAdapter';s getView()提供了不支持的操作异常:AdapterView中不支持addView(视图,布局参数),java,android,android-layout,listview,android-arrayadapter,Java,Android,Android Layout,Listview,Android Arrayadapter,我正在尝试创建一个列表视图,在我自己的布局中存储项目。我下面写我的代码。我在我的EventAdapter类的getView中遇到了一个异常,它似乎来自分配convertView。到目前为止,我所看到的一切都表明,这是分配convertView的正确方法,因此我不知道如何解决这个问题 这是我的定制阵列适配器: public class EventAdapter extends ArrayAdapter<Event> { public EventAdapter(Context

我正在尝试创建一个列表视图,在我自己的布局中存储项目。我下面写我的代码。我在我的EventAdapter类的getView中遇到了一个异常,它似乎来自分配convertView。到目前为止,我所看到的一切都表明,这是分配convertView的正确方法,因此我不知道如何解决这个问题

这是我的定制阵列适配器:

public class EventAdapter extends ArrayAdapter<Event> {

    public EventAdapter(Context context, int eventListItemId, ArrayList<Event> eventList) {
        super(context, eventListItemId, eventList);
    }

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

        // get the data of the event at this position
        Event event = getItem(position);

        if (convertView == null) {
            convertView = LayoutInflater.from(getContext())
                    .inflate(R.layout.event_list_item_layout, parent, false); 
            // ^^^^^^   The Exception is thrown above   ^^^^^^^
        }

        // get Textviews from event_list_item_layout
        TextView name = (TextView) convertView.findViewById(R.id.event_list_name);
        ...

        // set text on the TextViews
        name.setText(event.getName());
        ...

        return convertView;
    }
}
这是我想要列表的活动的布局(称为
search\u results\u activity
):


有人知道我哪里出了问题吗?

您好,您可以阅读这篇文章,希望他们的答案之一有效。我以前确实看过这篇文章。我没有看到任何真正有助于解决此问题的解决方案
LayoutInflater inflater=LayoutInflater.from(getContext())然后在if(convertView==null){..}块中do
View aview=inflater.inflate(R.layout.event\u list\u item\u layout,null,true)这也不起作用。错误是说,
inflater.inflate()
行正在调用addView()。有什么方法可以防止这种情况发生吗?请尝试从事件列表项目布局XML中删除ListView。希望对你有所帮助!您好,您可以阅读这篇文章,希望他们的答案之一是有效的。我以前确实看过这篇文章。我没有看到任何真正有助于解决此问题的解决方案
LayoutInflater inflater=LayoutInflater.from(getContext())然后在if(convertView==null){..}块中do
View aview=inflater.inflate(R.layout.event\u list\u item\u layout,null,true)这也不起作用。错误是说,
inflater.inflate()
行正在调用addView()。有什么方法可以防止这种情况发生吗?请尝试从事件列表项目布局XML中删除ListView。希望对你有所帮助!
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:gravity="center">

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1">

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

        ...
    </ListView>

    ...
</LinearLayout>
<?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="match_parent">

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

    <ListView
        android:id="@+id/event_list_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:divider="@color/colorAccent"
        android:dividerHeight="1dp" />


</LinearLayout>
java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
                      at android.widget.AdapterView.addView(AdapterView.java:478)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                      at com.mobiledevs.eventreminder.APIUtils.EventAdapter.getView(EventAdapter.java:38)