Spinner malfunctioning on Lollipop

纵饮孤独 提交于 2019-12-23 08:04:22

问题


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]));
}

回答1:


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.




回答2:


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/



来源:https://stackoverflow.com/questions/30315935/spinner-malfunctioning-on-lollipop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!