Home android Drop-down Android List

Drop-down Android List




Hello everyone, try to realize such a function as the drop-down list with the choice of elements as in the picture Enter here a description of the image
But I can not understand what instrument it was implemented. I tried to do in the Expandable ListView but ListView requires a place on the screen, and then everything is compressed and very convenient. You can tell which way to dig or tell the ready-made solution. The spinner does not work either since when I exhibit in the layout_widh 30-60dp parameter, the application creates when you press the spinner

Answer 1

You can create your own toolbar and there as an Item place the spinner

& lt; xml version = "1.0" encoding = "UTF-8"? & gt;
& lt; Menu XMLNS: Android = "http://schemas.android.com/apk/res/android"
XMLNS: App = "http://schemas.android.com/apk/res-auto" & gt;
& lt; item
Android: id = "@ + ID / Category_spinner"
Android: title = "@ STRING / ITEM_CATEGORY"
App: ActionViewClass = "Android.widget.spinner"
App: ShowASAction = "IFROOM" / & GT;

Next Create a layout for each Sport element

& lt; xml version = "1.0" encoding = "UTF-8"? & gt;
& lt; TextView XMLNS: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "Match_Parent"
Android: layout_height = "wrap_content"
Android: Padding = "5dp"
 Android: TextSize = "@ dimen / category_spinner_text_size" / & gt;

And then work with him in activati ​​

Public Class NewSlistActivity Extends AppCompatactivity {
  // Some Code.
  Public Boolean OnCreateOptionsMenu (Menu Menu) {
    getMenuinflater (). Inflate (R.Menu.Antivity_news_Menu_List, Menu);
    CreateSpinner (Menu);
  // Some Code.
  Private Void CreateSpinner (Menu Menu) {
    Menuitem CategorySpinner = Menu.FindItem (R.ID.category_spinner);
    Spinner Spinner = (Spinner) CategorySpinner.getActionView ();
    Arrayadapter & lt; String & GT; Adapter = New Arrayadapter & LT; & GT; (this,
      R.Layout.categoty_spinner_item, const.category_list);
    Spinner.Setadapter (Adapter);
    spinner.setselection (selectedcategory);
    spinner.setonitemselectedlistener (changecategorylistener);

This is an example of the Sport from my project, but I think everything is extremely clear here. If you are questions, write, supplement the answer.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions