public class

SchemaTypeListItemAdapter

extends RecyclerView.Adapter<SchemaTypeListItemAdapter.ViewHolder>

 java.lang.Object

androidx.recyclerview.widget.RecyclerView.Adapter<SchemaTypeListItemAdapter.ViewHolder>

↳androidx.appsearch.debugview.view.SchemaTypeListItemAdapter

Gradle dependencies

compile group: 'androidx.appsearch', name: 'appsearch-debug-view', version: '1.1.0-alpha05'

  • groupId: androidx.appsearch
  • artifactId: appsearch-debug-view
  • version: 1.1.0-alpha05

Artifact androidx.appsearch:appsearch-debug-view:1.1.0-alpha05 it located at Google repository (https://maven.google.com/)

Overview

Adapter for displaying a list of AppSearchSchema objects.

This adapter displays each schema type with its name.

Schema types can be manually changed by calling SchemaTypeListItemAdapter.setSchemaTypes(List).

Summary

Methods
public abstract intgetItemCount()

Returns the total number of items in the data set held by the adapter.

public abstract voidonBindViewHolder(RecyclerView.ViewHolder holder, int position)

Called by RecyclerView to display the data at the specified position.

public abstract RecyclerView.ViewHolderonCreateViewHolder(ViewGroup parent, int viewType)

Called when RecyclerView needs a new RecyclerView.ViewHolder of the given type to represent an item.

public voidsetSchemaTypes(java.util.List<AppSearchSchema> schemaTypes)

Sets the adapter's schema type list.

from RecyclerView.Adapter<VH>bindViewHolder, createViewHolder, findRelativeAdapterPositionIn, getItemId, getItemViewType, getStateRestorationPolicy, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, setStateRestorationPolicy, unregisterAdapterDataObserver
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public void setSchemaTypes(java.util.List<AppSearchSchema> schemaTypes)

Sets the adapter's schema type list.

Parameters:

schemaTypes: list of AppSearchSchema objects to update adapter with.

public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)

Called when RecyclerView needs a new RecyclerView.ViewHolder of the given type to represent an item.

This new ViewHolder should be constructed with a new View that can represent the items of the given type. You can either create a new View manually or inflate it from an XML layout file.

The new ViewHolder will be used to display items of the adapter using RecyclerView.Adapter. Since it will be re-used to display different items in the data set, it is a good idea to cache references to sub views of the View to avoid unnecessary View calls.

Parameters:

parent: The ViewGroup into which the new View will be added after it is bound to an adapter position.
viewType: The view type of the new View.

Returns:

A new ViewHolder that holds a View of the given view type.

See also: RecyclerView.Adapter.getItemViewType(int), RecyclerView.Adapter

public abstract void onBindViewHolder(RecyclerView.ViewHolder holder, int position)

Called by RecyclerView to display the data at the specified position. This method should update the contents of the RecyclerView.ViewHolder.itemView to reflect the item at the given position.

Note that unlike , RecyclerView will not call this method again if the position of the item changes in the data set unless the item itself is invalidated or the new position cannot be determined. For this reason, you should only use the position parameter while acquiring the related data item inside this method and should not keep a copy of it. If you need the position of an item later on (e.g. in a click listener), use RecyclerView.ViewHolder.getBindingAdapterPosition() which will have the updated adapter position. Override RecyclerView.Adapter instead if Adapter can handle efficient partial bind.

Parameters:

holder: The ViewHolder which should be updated to represent the contents of the item at the given position in the data set.
position: The position of the item within the adapter's data set.

public abstract int getItemCount()

Returns the total number of items in the data set held by the adapter.

Returns:

The total number of items in this adapter.

Source

/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.appsearch.debugview.view;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.appsearch.app.AppSearchSchema;
import androidx.appsearch.debugview.R;
import androidx.core.util.Preconditions;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

/**
 * Adapter for displaying a list of {@link AppSearchSchema} objects.
 *
 * <p>This adapter displays each schema type with its name.
 *
 * <p>Schema types can be manually changed by calling {@link #setSchemaTypes}.
 *
 * @exportToFramework:hide
 */
@RestrictTo(RestrictTo.Scope.LIBRARY)
public class SchemaTypeListItemAdapter extends
        RecyclerView.Adapter<SchemaTypeListItemAdapter.ViewHolder> {
    private List<AppSearchSchema> mSchemaTypes;

    SchemaTypeListItemAdapter(@NonNull List<AppSearchSchema> schemaTypes) {
        mSchemaTypes = Preconditions.checkNotNull(schemaTypes);
    }

    /**
     * Sets the adapter's schema type list.
     *
     * @param schemaTypes list of {@link AppSearchSchema} objects to update adapter with.
     */
    public void setSchemaTypes(@NonNull List<AppSearchSchema> schemaTypes) {
        mSchemaTypes = Preconditions.checkNotNull(schemaTypes);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.adapter_schema_type_list_item, parent, /*attachToRoot=*/false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        String schemaType = mSchemaTypes.get(position).getSchemaType();

        holder.getSchemaTypeLabel().setText(schemaType);
    }

    @Override
    public int getItemCount() {
        return mSchemaTypes.size();
    }

    /**
     * ViewHolder for {@link SchemaTypeListItemAdapter}.
     */
    public static class ViewHolder extends RecyclerView.ViewHolder {
        private final TextView mSchemaTypeLabel;

        public ViewHolder(@NonNull View view) {
            super(view);

            Preconditions.checkNotNull(view);

            mSchemaTypeLabel = view.findViewById(R.id.schema_type_item_title);
        }

        @NonNull
        public TextView getSchemaTypeLabel() {
            return mSchemaTypeLabel;
        }
    }
}