简体   繁体   English

在微调器 Android Studio 中遇到问题

[英]Getting Problem In Spinner Android Studio

I was making an app.我正在制作一个应用程序。 I am trying to add a scrollable spinner in my Android App shown in the given image below.我正在尝试在我的 Android 应用程序中添加一个可滚动的微调器,如下图所示。 But I have attempted many codes but I failed to get proper results.但是我尝试了很多代码,但没有得到正确的结果。 The main problem is that when I am implementing a spinner in my android app and when I add an adapter in it, it works like a normal dropdown spinner but I have too many items for my spinner and I want someone to scroll when he or she clicks on the spinner.主要问题是,当我在我的 android 应用程序中实现一个微调器时,当我在其中添加一个适配器时,它就像一个普通的下拉微调器一样工作,但是我的微调器有太多项目,我希望有人在他或她时滚动点击微调器。

I want to make spinner like this:=我想做这样的微调器:=

After trying my code I can't scroll the spinner it was showing normal dropdown items尝试我的代码后,我无法滚动显示正常下拉项目的微调器

Please answer if anyone have any solution请回答如果有人有任何解决方案

In the following image, I can scroll the spinner and select the desired item在下图中,我可以滚动微调器和 select 所需的项目在此处输入图像描述

You can check this image I want to make a same scrollable spinner, Now here is the code which I tried -您可以查看此图像我想制作一个相同的可滚动微调器,现在这是我尝试过的代码 -

<Spinner
        android:id="@+id/test_spinner"
        android:layout_width="50dp"
        android:layout_height="match_parent"
        android:spinnerMode="dropdown"/>

Java -- Java --

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.days, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);

Via reflection, access private mPopup通过反射,访问私有 mPopup

Spinner spinner = (Spinner) findViewById(R.id.your_spinner);
  try {
    Field popup = Spinner.class.getDeclaredField("mPopup");
    popup.setAccessible(true);
    //private mPopup 
    android.widget.ListPopupWindow popupw = (android.widget.ListPopupWindow)      popup.get(spinner);
popupw.setHeight(500);//height in px
}
catch (Exception ex) {
    // print
}

The only issue is that you are using editText with spinner and when spinner opens keyboard also open then your spinner items hiding behind the keyboard so solution is just use spinner without editText.唯一的问题是您正在使用带有微调器的editText,并且当微调器打开键盘时也会打开,然后您的微调器项目隐藏在键盘后面,因此解决方案只是使用没有editText的微调器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM