is there any method to add custom class arraylist to the spinner with hint?

kindly anyone answer me the solution of how to add custom class Arraylist to the spinner with hint but when we open the dropdown hint must not be shown in the dropdown only Arraylist is shown in the drop down.

    sDate.setAdapter(adapter)
    sDate.setOnSpinnerItemClickListener(onSpinnerItemClickListener<String> {

            position, itemAtPosition -> {
        var item = itemAtPosition as DateRangeDataModel
    }


    })
    /*sDate.onItemSelectedListener =
        object : AdapterView.OnItemSelectedListener {
            override fun onItemSelected(
                parent: AdapterView<*>,
                view: View?,
                pos: Int,
                id: Long
            ) {
                var item = parent.selectedItem as DateRangeDataModel
                when (item.date) {
                    getString(R.string.select_dates) -> {

                        etFrom.isEnabled = true
                        etTo.isEnabled = true
                    }
                    "Select" -> {
                        //Do nothing
                    }
                    else -> {
                        etFrom.isEnabled = false
                        etTo.isEnabled = false
                    }
                }}
            override fun onNothingSelected(parent: AdapterView<*>) {

            }
        }*/
    var list1 = ArrayList<DateRangeDataModel>()
    list1.add(DateRangeDataModel("Select"))
    list1.add(DateRangeDataModel("Islamabad"))
    list1.add(DateRangeDataModel("Rawalpindi"))
    list1.add(DateRangeDataModel("Karachi"))
    list1.add(DateRangeDataModel("Lahore"))
    val adapter1 = CustomArrayAdapter(
        requireContext(),
        R.layout.spinner_single_textview, list1
    )
    sLocation.adapter = adapter1

Answer

Here is the solution of the quetion mentioned above..i have implemented this code in my project..Thank me later..

public class CustomArrayAdapter extends ArrayAdapter {

private final LayoutInflater mInflater;
private final Context mContext;
private final List<DateRangeDataModel> items;
private static final int DEFAULT_LAYOUT_RESOURCE = R.layout.spinner_single_textview;
private  final int layoutResource;
private  final String hintResource;
private final LayoutInflater layoutInflater;

public CustomArrayAdapter(@NonNull Context context, ArrayList  items,
                          @NonNull int layoutResource,  String hintResource) {
    super(context, 0, items);

    mContext = context;
    mInflater = LayoutInflater.from(context);
    this.items = items;
    this.layoutResource = layoutResource;
    this.hintResource = hintResource;
    this.layoutInflater = LayoutInflater.from(context);
}

@Override
public View getDropDownView(int position, @Nullable View convertView,
                            @NonNull ViewGroup parent) {
    return getCustomView(position,convertView, parent);
}

@Override
public @NonNull
View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    Log.d(TAG, "position: " + position + ", getCount: " + getCount());
    View view;
    if (position ==0) {
        view = getDefaultView(parent);
    } else {
        view = getCustomView(position, convertView, parent);
    }
    return view;
}


private View inflateDefaultLayout(ViewGroup parent) {
    return inflateLayout(DEFAULT_LAYOUT_RESOURCE, parent, false);
}

private View inflateLayout(int resource, android.view.ViewGroup root, boolean attachToRoot) {
    return layoutInflater.inflate(resource, root, attachToRoot);
}

protected View getCustomView(int position, View convertView, ViewGroup parent) {
    View view = inflateDefaultLayout(parent);
    DateRangeDataModel model = items.get(position);
    TextView textView = (TextView) view.findViewById(R.id.tvSpinnerTitle);
    if (model.getTitle()=="")textView.setVisibility(View.GONE);
    else textView.setText(model.getTitle());
    textView.setHint("");
    return view;
}

private View getDefaultView(ViewGroup parent) {
    View view = inflateDefaultLayout(parent);
    TextView textView = (TextView) view.findViewById(R.id.tvSpinnerTitle);
    textView.setText("");
    textView.setHint(hintResource);
    return view;
}

@Override
public boolean isEnabled(int position) {
    return position!=0;
}

}