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 9100113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:47:14+00:00 2026-06-17T00:47:14+00:00

I am a beginner in android….I need your help. In my app I created

  • 0

I am a beginner in android….I need your help.

In my app I created a listview using custom adapter and custom row layout. I am successful in doing so & I have added one image, textview and a spinner drop down in all rows. In the drop down there is number of items (from 0 to 9 for eg.)

But my problem is when I select drop down and set some value, on scrolling the list the spinner resets itself to initial value (here 0)..I am using a String of values 0 to 9 for Spinner.

What can I do to avoid this issue? Any help would be greatly appreciated….Thanks in advance.

//This is my custom adapter code....

public class MyProductsArrayAdapter extends ArrayAdapter<Products> {
Context context;
int resourceId;

Products data[] = null;

public MyProductsArrayAdapter(Context context, int resourceId,
        Products data[]) {
    super(context, resourceId, data);
    this.context = context;
    this.resourceId = resourceId;

    this.data = data;
}

static class ProductsItemViewHolder {

    ImageView image;
    TextView name;
    Spinner number;
}

String[] mArray = new String[] { "0", "1", "2", "3", "4", "5", "6", "7",

        "8", "9" };

public View getView(final int position, View convertView, ViewGroup parent) {
    View rowView = convertView;
    ProductsItemViewHolder holder = null;

    LayoutInflater mInflater = (LayoutInflater) context

            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (rowView == null) {

        rowView = mInflater.inflate(R.layout.main2, parent, false);
        holder = new ProductsItemViewHolder();
        holder.image = (ImageView) rowView.findViewById(R.id.item_icon);

        holder.name = (TextView) rowView.findViewById(R.id.tvListItemText);
        holder.number = (Spinner) rowView.findViewById(R.id.NumberSpinner);

        rowView.setTag(holder);

    } else {


        holder = (ProductsItemViewHolder) rowView.getTag();
    }

    Products f = data[position];
    holder.image.setImageResource(f.itemIcon);
    holder.name.setText(f.itemName);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,

            android.R.layout.simple_spinner_item, mArray);

    holder.number.setAdapter(adapter);

    return rowView;

}
}

//And here is my row_layout code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:orientation="horizontal" >

<ImageView
    android:id="@+id/item_icon"
    android:layout_width="40dp"
    android:layout_height="40dip"

    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="10dip"
    android:gravity="center_vertical"

    android:src="@drawable/ic_launcher" >
</ImageView>

<TextView
    android:id="@+id/tvListItemText"
    android:layout_width="wrap_content"

    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginLeft="10dp"
    android:layout_toRightOf="@id/item_icon"

    android:maxWidth="180dp"
    android:maxLines="2"
    android:text="Hello testing"
    android:textColor="@color/brown"
    android:textSize="15dp"

    android:typeface="normal" />

<Spinner
    android:id="@+id/NumberSpinner"
    android:layout_width="80dp"
    android:layout_height="wrap_content"

    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="0dp" />

</RelativeLayout>
  • 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-17T00:47:15+00:00Added an answer on June 17, 2026 at 12:47 am

    in the getView() of your List’s adapter, you must call YOUR_SPINNER.setSelected(position you set earlier);

    This is happening because, once the list is created you are always getting the convertView in getView and as its default stae of spinner in it is 0 position it gets there.

    Also, you are doing setAdapter to spinner always in getView method, so this will always initialize it when ever getView() will be called ie. on scrolling the list.

    What I am saying is set setOnItemSelectedListener() on your spinner and in onItemSelected() method of this listener set the value as the tag of your spinner object.
    holder.number.setTag(POSITION)

    After the statement holder.number.setAdapter() do holder.number.setSelection(Integer.parseInt(number.getTag));

    This way you are saving the value you selected, and you are setting the same index to it when ever the getView() is called.

    Editted:

    yes, set the value you got as parameter in method onItemSelected(View v, int arg2).
    This arg2 is the position system is telling you that this position is selected by you for this spinner (simple callback provided by the system).
    Now, in the same method’s implementation, you must set this value as the tag of this view object, which is the first argument of this callback.

    Also, if you are not getting this tag value in getView() you must initialize your spinner every time instead of getting it from convertView, as it might contain the reused view of the row which is not in view.

    Also, if you continue to get problem in implementing what I have said, you van follow another approach that make a static HashTable<integer, integer> where key would be the index of row and value will be the index of spinner item selected.

    So, in getView you can set holder.number.setSelection(hashtable.get(position));

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm beginner in android and I need to create own QR code scanner app.
I am a beginner in android.I need to design my layout as given in
Iam a beginner in android project development. I have started developing a basic app
I am a beginner in Android. I created an activity for the first screen,
I'm beginner in Android development, I'm working at my fisrt app and I met
I am beginner in android application development. If i am using n number of
I'm a beginner in Android. I use Eclipse to program my app. When I
I am a beginner of Android apps and am using Eclipse. I have found
I'm a beginner in android and at the moment, I'm working on simple app.
I am pure beginner to [android-eclipse],here i need to consume web services from the

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.