0

I am having an identical problem to what was described in this other stackoverflow thread, however after trying out the answers in that thread the problem remains unsolved.

Here's the current situation: I have an application that works for a handheld android device, and we are looking to use it on some larger tablets.

The spinners display properly on the smaller handhelds, but on the tablets the spinner's selected item text will not display. Selecting the dropdown will show the values normally as expected. It is only the closed dropdown that does not show the values.

Images of Issue

Changing Font/Background Color does not resolve the issue.

Using adapter.notifyDataSetChanged() after the dataset updates does not resolve the issue.

I have tried using wrap_content, 70dp, and 70sp for height as well to ensure it isn't a sizing issue

HandHeld Info

  • Android Oreo 8.1

Tablet Info

  • Samsung Galaxy Tab A (8 inch)
  • Android Oreo 8.1
  • Nexus Experience 9.5

LinearLayout the Spinner is in:

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

Code for Spinner

<Spinner
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/mech" />

Spinner Values Assignment:

var response = await this.api.GetMechanics();

var adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);

foreach (var mech in response.Data)
    adapter.Add(mech.code);

this.mySpinner.Adapter = adapter;

App create and usings:

using Android.App;
using Android.Support.V7.App;
using Android.Support.V7.Widget;
using Android.Widget;
using System;

namespace MyProject
{
    [Activity(Label = "MyProject", MainLauncher = true, ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]
    public class Main : AppCompatActivity
    {
        AppCompatSpinner _mech;

        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            this._mech = FindViewById<AppCompatSpinner>(Resource.Id.mech);
        }
}
Daniel Dees
  • 182
  • 2
  • 14
  • Show us your xml file and code. By the way, difference between handheld and tablets should only be on your xml designs and not in the code or logic. – Davi Mar 04 '19 at 17:09
  • Relevant spinner code added at bottom, Also added a link to screenshots of the issue @Davi – Daniel Dees Mar 04 '19 at 18:38
  • 1
    I remember I had a similar issue and it was something related to styles, i also used `AppCompatSpinner` in place of `Spinner` – FreakyAli Mar 04 '19 at 20:46
  • @G.hakim I could see it possibly being related to the styles. The new tablets we are testing the app on have a different UI theme/appearance than the handheld devices. Is there a way to ensure the app theme is identical for all devices it is installed on? – Daniel Dees Mar 05 '19 at 15:48
  • 1
    I am not talking about that style I am talking about the spinner style, are you using any styles there is my point. – FreakyAli Mar 05 '19 at 16:08
  • @G.hakim No I do not believe so, all the code relevant to the spinner is listed in my code snippet in the post. The only other thing I can think of is with the linearlayout style: – Daniel Dees Mar 05 '19 at 16:12
  • 1
    Are you using the Android support libraries? – FreakyAli Mar 05 '19 at 16:16
  • @G.hakim No. Which ones should I be including? Both the devices we are using are running Oreo 8.1 – Daniel Dees Mar 05 '19 at 16:17
  • 1
    Android support libraries are a must you should always use them check this https://blog.xamarin.com/mastering-android-support-libraries/ – FreakyAli Mar 05 '19 at 16:19
  • 1
    And what I am suggesting is you use `Android.Support.V7.Widget.AppCompatSpinner` in place of your normal spinner – FreakyAli Mar 05 '19 at 16:21
  • @G.hakim Ok, So I Converted it all to AppCompatSpinners, then I had to update my activity from Main : Activity to Main : AppCompatActivity. I got an error with inflating the layout at that point and I'm not sure where to go from here. – Daniel Dees Mar 05 '19 at 16:53
  • 1
    You should check this : https://blog.xamarin.com/android-tips-hello-appcompatactivity-goodbye-actionbaractivity/ the issue is because your activity does not have a theme this will solve that – FreakyAli Mar 05 '19 at 16:55
  • @G.hakim Hey thank you for helping me so far, I know this may be getting a bit annoying but I think I'm making progress. So I've gone through that and added in the styles files/folders with a direct copy-paste of the example code they had given. The UI updated to reflect the new theme so that's working. However I'm getting this error: Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class Android.Support.V7.Widget.AppCompatSpinner I searched it and the solutions were saying to remove the android: prefix, however I don't have those. Any ideas? – Daniel Dees Mar 05 '19 at 17:58
  • 1
    Actually you must not be having the support library needed wait let me find it – FreakyAli Mar 05 '19 at 18:27
  • 1
    Can you look for `Android.Support.V7.Widget.AppCompatSpinner` in a cs file and see if it is available in your project!? If you are not able to find it you are missing the V7 support library just add it and you are good – FreakyAli Mar 05 '19 at 18:37
  • @G.hakim It is already included at the top of the file: using Android.Support.V7.App; using Android.Support.V7.Widget; I also do have the Xamarin package for it installed as well. – Daniel Dees Mar 05 '19 at 18:39
  • 1
    Look for the exact control and if it is not there look for it on nuget and add the package is what i mean – FreakyAli Mar 05 '19 at 18:46
  • @G.hakim Ok, I decided to try and narrow some things down. So I've commented out the entire activities code except for where I set the contentview. I get the same inflation error. I have the xamarin files downloaded https://imgur.com/a/QsBd568 and they are all included in the references section of my project. My spinner code (the only thing in the axml file now) is Should we move to chat instead of comments? – Daniel Dees Mar 05 '19 at 19:09
  • 1
    Look for `Android.Support.V7.Widget.AppCompatSpinner` on nuget may be? – FreakyAli Mar 05 '19 at 19:34
  • @G.hakim It doesn't seem to exist. The search I used was for all packages that were Support.V7 a google search doesn't show anything either. However I am not getting any syntax errors when referencing it from within my cs file so it appears that I do in fact have AppCompatSpinner. It is the reference to it in the axml file that is giving the issue. If I comment out the button code I posted in my last comment, the app runs fine. – Daniel Dees Mar 05 '19 at 19:39
  • @G.hakim Oh my lord... You have to reference the spinner as a spinner in the axml, but as an AppCompatSpinner in the .cs file. You can't create it as an appcompatspinner in the axml.... It compiles now... I'm going to push this live to one of our tablets and see if it works – Daniel Dees Mar 05 '19 at 20:00
  • @G.hakim It works! now I just need to convert back to the old dark theme from the light one and I'm done! Thank you so much! – Daniel Dees Mar 05 '19 at 20:16

0 Answers0