Change position of items when the spinner is selected.

SiflouSiflou ✭✭USMember ✭✭

Hey Guys, I have a spinner, when I click on it, the items in the adapter are centered in the screen. Is there a way to change its position, so I could like align them just below my spinner to make a kind of drop down list ? Thanks a lot for your time !

Claude

Posts

  • StevenTheEvenStevenTheEven ✭✭✭ SEMember ✭✭✭
    edited May 2013

    http://forums.xamarin.com/discussion/261/how-to-assign-custom-object-to-spinner

    cityAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);

  • SiflouSiflou ✭✭ USMember ✭✭

    Thanks for the reply, the problem is that my spinner item is custom so when I inflate my layout, it isnt the simpleSpinnerDropDown, it is my custom, my code looks like this (For now the getdropdown and getview are the same but you will get the point):

    `
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;

    //
    using MaitreD_Dashboard.Core.Database;

    namespace MaitreD_Dashboard.Android
    {
    class RestaurantSelectionAdapter : BaseAdapter,ISpinnerAdapter
    {
    //
    List mRestaurants = DBManager.GetSingleton ().GetRestaurants();

        Activity mActivity;
    
        global::Android.Graphics.Typeface mCondensedFont;
    
        public RestaurantSelectionAdapter (Activity activity)
        {
            mActivity = activity;
    
            mCondensedFont = global::Android.Graphics.Typeface.CreateFromAsset(mActivity.Assets, "fonts/Interstate-BoldCondensed.otf");
        }
    
        public override int Count {
            get { return mRestaurants.Count; }
        }
    
        public override long GetItemId (int position) {
            return long.Parse(mRestaurants [position].RestaurantId);
        }
    
        public override Java.Lang.Object GetItem (int position) {
            // could wrap a Contact in a Java.Lang.Object 
            // to return it here if needed
            return null;
        }
        public override View GetView (int position, View convertView, ViewGroup parent)
        {        
            return GetCustomView (position, convertView, parent, false);
        }
    
        public override View GetDropDownView (int position, View convertView, ViewGroup parent)
        {        
            return GetCustomView (position, convertView, parent, true);
        }
    
        private View GetCustomView(int aPosition,View aConvertView, ViewGroup aParent,bool aDropDown)
        {
            //
            View view = aConvertView ?? mActivity.LayoutInflater.Inflate (
                Resource.Layout.RestaurantSelectionAdapter, aParent, false);
    
            //
            TextView lblRestaurant = view.FindViewById<TextView> (Resource.Id.lblRestaurantAdapter);
            TextView lblCity = view.FindViewById<TextView> (Resource.Id.lblCityAdapter);
    
            //
            lblRestaurant.SetTypeface (mCondensedFont, global::Android.Graphics.TypefaceStyle.Normal);
            lblCity.SetTypeface (mCondensedFont, global::Android.Graphics.TypefaceStyle.Normal);
    
            //
            lblRestaurant.Text = mRestaurants [aPosition].RestaurantName;
            lblCity.Text = mRestaurants [aPosition].RestaurantCity;
    
            return view;
        }
    
    }
    

    }

    `
    Can somebody help me please :) Thanks a lot !

  • StevenTheEvenStevenTheEven ✭✭✭ SEMember ✭✭✭

    Only to be clear, if you use the "standard"-SimpleSpinnerDropDownItem it works at it should but it looks "ugly"? ;)

  • SiflouSiflou ✭✭ USMember ✭✭

    yes

Sign In or Register to comment.