Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have these, but after running the program, I do not see any output on emulator.

MySpinnerAdapter.cs
namespace spinnerTest
{
    public class MySpinnerAdapter : ArrayAdapter<String>
    {
        Typeface font = Typeface.CreateFromAsset(Application.Context.Assets, "fonts/MYFONT.TTF");
        public MySpinnerAdapter(Context context, int resource, String[] items)
            : base(context, resource, items)
        {

        }
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            TextView view = (TextView)GetView(position, convertView, parent);
            view.SetTypeface(font, TypefaceStyle.Normal);
            return view;
        }

        public override View GetDropDownView(int position, View convertView, ViewGroup parent)
        {
            TextView view = (TextView)GetDropDownView(position, convertView, parent);
            view.SetTypeface(font, TypefaceStyle.Normal);
            return view;
        }
    }
}


textview_with_padding
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee" />


Main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Spinner
        android:id="@+id/spinner2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>


MainActivity.cs
namespace spinnerTest
{
    [Activity(Label = "spinnerTest", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
            String[] spinnerItems = new String[]{
                "Aa",
                "Bbb",
                "Cccc",
                "Ddddd",
                "Ee",
            };

            Spinner SpinnerWithPadding = (Spinner)FindViewById(Resource.Id.spinner2);
            ArrayAdapter<String> spinnerArrayAdapter = new MySpinnerAdapter(this, Resource.Layout.textview_with_padding, spinnerItems);
            spinnerArrayAdapter.SetDropDownViewResource(Resource.Layout.textview_with_padding);
            SpinnerWithPadding.Adapter = spinnerArrayAdapter;
        }
    }
}


What I have tried:

I do not have any error but I do not have output on Emulator.
Posted
Updated 29-Apr-18 6:03am

1 solution

I found:
My problem was in MySpinnerAdapter.cs:
I had not used base for GetView (base.GetView) and GetDropDownView (base.GetDropDownView).

TextView view = (TextView)base.GetView(position, convertView, parent);
TextView view = (TextView)base.GetDropDownView(position, convertView, parent);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900