Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8198235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:54:32+00:00 2026-06-07T05:54:32+00:00

I have a spinner with a custom adapter that I used to set the

  • 0

I have a spinner with a custom adapter that I used to set the height of the first element in the spinner drop down to zero. I do this to have a default message in my spinner (first element) without the user being able to click it, since it’s not visible.

package org.digitalhealthagency.elaj.util;

import java.util.ArrayList;

import org.digitalhealthagency.elaj.gui.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

public class CustomAdapter extends ArrayAdapter implements SpinnerAdapter{

    Context context;
    int textViewResourceId;
    ArrayList arrayList;

    public CustomAdapter(Context context, int textViewResourceId,  ArrayList arrayList) {
        super(context, textViewResourceId, arrayList);

        this.context = context;
        this.textViewResourceId = textViewResourceId;
        this.arrayList = arrayList;

    }

    @Override
     public View getDropDownView(int position, View convertView, ViewGroup parent){
       if (convertView == null)
       {
         LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         //convertView = vi.inflate(android.R.layout.simple_spinner_dropdown_item, null);
         convertView = vi.inflate(R.layout.spinner_item, null);
       }

       TextView textView = (TextView) convertView.findViewById(android.R.id.text1);
       textView.setText(arrayList.get(position).toString());//after changing from ArrayList<String> to ArrayList<Object>

       if (position  == 0) { 
          textView.setHeight(0);
      }
      else{
        textView.setHeight(100);
      }

       return convertView;
     }



}

In the getDropDownView I am trying to inflate with spinner_item.xml instead of android.R.layout.simple_spinner_dropdown_item. My spinner_item looks as follows,

<?xml version="1.0" encoding="utf-8"?>

  <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
    android:gravity="right|center_vertical"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:paddingRight="10dp"
    android:ellipsize="marquee" /> 

And in my activity code, I use the adapter as follows,

        CustomAdapter adapter = new CustomAdapter(this, R.layout.spinner, subSpecialities);
        adapter.setDropDownViewResource(R.layout.spinner_item);
        mSubSpecialtySpinner.setAdapter(adapter);

I get the following error in my log cat,

07-10 10:49:34.103: E/AndroidRuntime(518): FATAL EXCEPTION: main
07-10 10:49:34.103: E/AndroidRuntime(518): java.lang.NullPointerException
07-10 10:49:34.103: E/AndroidRuntime(518):  at org.digitalhealthagency.elaj.util.CustomAdapter.getDropDownView(CustomAdapter.java:40)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:569)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:565)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.AbsListView.obtainView(AbsListView.java:2033)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.ListView.onMeasure(ListView.java:1155)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.View.measure(View.java:12723)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.View.measure(View.java:12723)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.View.measure(View.java:12723)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.View.measure(View.java:12723)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.View.measure(View.java:12723)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-10 10:49:34.103: E/AndroidRuntime(518):  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.View.measure(View.java:12723)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.os.Looper.loop(Looper.java:137)
07-10 10:49:34.103: E/AndroidRuntime(518):  at android.app.ActivityThread.main(ActivityThread.java:4424)
07-10 10:49:34.103: E/AndroidRuntime(518):  at java.lang.reflect.Method.invokeNative(Native Method)
07-10 10:49:34.103: E/AndroidRuntime(518):  at java.lang.reflect.Method.invoke(Method.java:511)
07-10 10:49:34.103: E/AndroidRuntime(518):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-10 10:49:34.103: E/AndroidRuntime(518):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-10 10:49:34.103: E/AndroidRuntime(518):  at dalvik.system.NativeStart.main(Native Method)

Could anyone please help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:54:33+00:00Added an answer on June 7, 2026 at 5:54 am

    textView is null so NPE..change it in R.id.text1 instead of android.R.id.text1

    TextView textView = (TextView) convertView.findViewById(android.R.id.text1);
                                                            ^^^^^^^^     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom spinner that uses two custom views, one for the drop
I have a spinner set up like this: ArrayAdapter<String> states = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,
I have a custom View class that extends Spinner. I'm trying to figure out
I have a spinner with a custom adapter displaying objects from a database. When
I have created a custom Array Adapter to bind a custom row that contains
I've created a custom adapter for my spinner because I wanted to have multiple
I have a custom implementation of an Array Adapter that I'm using in a
I have a spinner getting views from a custom base adapter. The problem is
I have a custom 9-patch image for my spinner. This image works fine on
I have an app where the user presses a button and a custom spinner

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.