Java 传递给ArrayAdapter和RecyclerView适配器的视图和视图组是什么?

Java 传递给ArrayAdapter和RecyclerView适配器的视图和视图组是什么?,java,android,Java,Android,我对最初传递给方法的内容非常困惑 在ArrayAdapter getview方法中,传递的视图和视图组是什么 public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { View listItemView = convertView; if (listItemView == null) { listItemView = LayoutI

我对最初传递给方法的内容非常困惑

在ArrayAdapter getview方法中,传递的
视图
视图组
是什么

 public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View listItemView = convertView;
        if (listItemView == null) {
            listItemView = LayoutInflater.from(getContext()).inflate(
                    R.layout.list_item, parent, false);
        }
            ....

        }
列表项xml为

<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"
    android:weightSum="1">


    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.09"
        android:fontFamily="serif"

        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:textColor="#000000"
        android:textSize="20sp"
        android:textStyle="bold" />

    ....
</LinearLayout>
编号\u列表\u项目为

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp">

    <TextView
        android:id="@+id/tv_item_number"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|start"
        android:fontFamily="monospace"
        android:textSize="42sp"
        tools:text="#42" />
</FrameLayout>
当您想在UI上显示任何视图时,它必须具有一定的高度和宽度。在
充气方法中

  • 第一个参数是视图的资源id,它应该膨胀。在适配器的情况下,它应该是要回收的项目视图

  • 第二个参数是
    视图组
    ,通常为父视图。父视图必须是视图组,因为视图组包含子视图,反之亦然。在
    列表视图的情况下
    有时未自动采用的膨胀视图的大小(宽度)取决于其父视图

例如,如果
列表视图
具有宽度
匹配父视图
,则如果跳过此参数,则膨胀视图的宽度可能小于其父视图的宽度

  • 第三个参数用于决定是否要在父视图组中添加膨胀视图(第二个参数)。在
    列表视图
    的情况下,如果将其设置为真,则将获得
    运行时异常
    视图
    已具有父视图),如果要在父视图中添加新视图,则此参数应为真
例如,如果我只想在突然操作后在UI中添加
视图
,那么我将膨胀“视图”并添加
视图组

当您想在UI上显示任何视图时,它必须具有一定的高度和宽度。在
充气方法中

  • 第一个参数是视图的资源id,它应该膨胀。在适配器的情况下,它应该是要回收的项目视图

  • 第二个参数是
    视图组
    ,通常为父视图。父视图必须是视图组,因为视图组包含子视图,反之亦然。在
    列表视图的情况下
    有时未自动采用的膨胀视图的大小(宽度)取决于其父视图

例如,如果
列表视图
具有宽度
匹配父视图
,则如果跳过此参数,则膨胀视图的宽度可能小于其父视图的宽度

  • 第三个参数用于决定是否要在父视图组中添加膨胀视图(第二个参数)。在
    列表视图
    的情况下,如果将其设置为真,则将获得
    运行时异常
    视图
    已具有父视图),如果要在父视图中添加新视图,则此参数应为真
例如,如果我只想在突然操作后在UI中添加
视图
,那么我将膨胀“视图”并添加
视图组


您好,是视图组,它是在LISTVIEW的xml布局或list_item xml中定义的父视图。ItemView的父视图在您的视图中有一个直接的父视图LISTVIEW或RecyclerViewcase@raxx我建议您,如果检查viewGrouo是否为ListView/RecyclerView的实例,仅用于测试目的,请写入,最初,当系统调用ConverterView时,它将为null,并且ViewGroup将是List_项的ListView(即使ListView在单独的xml中)?对于recyclerAdapter,视图组将是RecycleView??右@raxx.Hi,是视图组,是在LISTVIEW的xml布局中定义的父视图或list_item xml.Parent,您的视图中有一个直接的父LISTVIEW或RecyclerViewcase@raxx我建议您,如果检查viewGrouo是否为ListView/RecyclerView的实例,仅用于测试目的,请写入,最初,当系统调用ConverterView时,它将为null,并且ViewGroup将是List_项的ListView(即使ListView在单独的xml中)?对于recyclerAdapter,视图组将是RecycleView??没错,就是raxx。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp">

    <TextView
        android:id="@+id/tv_item_number"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|start"
        android:fontFamily="monospace"
        android:textSize="42sp"
        tools:text="#42" />
</FrameLayout>
View view = inflater.inflate(layoutIdForListItem, viewGroup, shouldAttachToParentImmediately
    View view = inflater.inflate(layoutIdForListItem, viewGroup, 
                                 shouldAttachToParentImmediately);