Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spinner malfunctioning on Lollipop

My Android Project Build Target is 5.1.1 API 22

This app seems to work for every OS version except Lollipop. Lollipop restructures the height of some activities (negating the scrollable layout) as well as disrupts the spinners.

Clicking a specific position on a spinner will input a different position in the app. I'm not sure why and I don't know how to fix this. In some cases, even if you click a button on the spinner, it registers the bottom most visible button on the spinner. For some spinners, it won't allow the user to scroll at all.

One of my malfunctioning spinner codes is like this:

ArrayAdapter<String>adapterl4 = new ArrayAdapter<String>(this,
        android.R.layout.simple_spinner_item,hbmlevel){ 
            public boolean isEnabled(int position){
                displayData(position);
                return true;
            }
        };
selecthbm = (Spinner)findViewById(R.id.selecthbmlvl);
adapterl4.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
selecthbm.setAdapter(adapterl4);
selecthbm.setOnItemSelectedListener(this);

I've also tried using a global variable for the function displayData but I still get the same results.

The app is a very basic app that you can download here and is running on Java Compiler Compliance level 1.7

The beginning of my xml looks like this:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:fillViewport="true"
    android:background="#C2DFFF">

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

displayData:

public void displayData(int pos){

    herolvlTV.setText(hbmherolvl[pos]);
    hbmshardTV.setText(getResources().getString(R.string.shards)+" " +String.valueOf(hbmshards[pos]));
    hbmexpTV.setText(getResources().getString(R.string.maxexp)+" " +String.valueOf(hbmmaxexp[pos]));
}
like image 973
krikara Avatar asked May 19 '15 02:05

krikara


2 Answers

Here's the issue :

ArrayAdapter<String>adapterl4 = new ArrayAdapter<String>(this,
        android.R.layout.simple_spinner_item,hbmlevel){ 
            public boolean isEnabled(int position){
                displayData(position);
                return true;
            }
        };

The isEnabled function simply does not work on Lollipop. The solution is to change selecthbm.setOnItemSelectedListener(this); into selecthbm.setOnItemSelectedListener(new OnItemSelectedListener(){...}); and remove the isEnabled function in its entirety.

I don't know why the isEnabled function doesn't work though. If anyone wants to provide an explanation, I can award the bounty.

like image 77
krikara Avatar answered Sep 29 '22 19:09

krikara


The implementation in lollipop n pre lollipop are different, though I can't analyse your code and provide a ready made solution, I hope u find ur solution here

https://blog.danielbetts.net/2015/01/02/material-design-spinner-toolbar-style-fix/

like image 32
sapamlucy Avatar answered Sep 29 '22 21:09

sapamlucy