ListView is not displayed in the visual editor. Only: Item 1 Sub Item 1; Item 2 Sub Item 2; Item 3 Sub Item 3 , etc. to the end of the screen. enter image description here LinearLayout is used in vertical orientation. And two ListViews are not located one above the other, but one above the other (this is only in the visual editor. In this case, I am interested in a visa. Editor).

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <ListView android:id="@+id/list_options1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:entries="@array/options1" /> <ListView android:id="@+id/list_options2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:entries="@array/options2" /> </LinearLayout> 

strings.xml

 <resources> <string name="app_name">Простейшее</string> <string-array name="options1"> <item>Пункт_1</item> <item>Пункт_2</item> <item>Пункт_3</item> </string-array> <string-array name="options2"> <item>Пункт_4</item> <item>Пункт_5</item> <item>Пункт_6</item> </string-array> </resources> 

Well, the MainActivity that the studio has created.

I tried to place two ListViews not one under the other, but side by side with the horizontal orientation LinearLayout well, and, of course, changed android: layout_width, android: layout_height to wrap_content . The result is the same as in the first case - only Item 1 Sub Item 1; Item 2 Sub Item 2; Item 3 Sub Item 3 , etc. Just starting to figure it out. Help me please

    1 answer 1

    List items and should not be displayed in the visual editor. What you see is just a preview (a picture with the position of the widgets on the screen), and not a full emulator. After all, in order to fill the item with data, the code must be executed, and this is possible only in the emulator or the real device, respectively, to see the actual appearance of your application, you need to run your program (green triangle in the toolbar).

    If it is still important for you to see your items on the preview, you can spend extra time on meaningless, in general, decoration and take advantage of the tools XML markup namespace . In particular, tools:listitem , which will draw you the desired item, but also with restrictions, for example, it will be filled with template, and not actual data. You can solve this problem through the tools:sample attribute, which will substitute the previously prepared data.

    An example of working with a list through the tools tool. Let me remind you that in this case you will not see what will actually happen with the work of your program. Some kind of data that you separately prepare in advance specifically for this purpose will simply be substituted.

    The question is whether all this is necessary .. In any case, the preview only gives a rough idea of ​​what will be on the screen - this is not executable code, but a render and that it shows you should not rely (otherwise you will have surprises when you start on the device). For a complete idea of ​​what happened and how it will look on the screen, you need to test only on an emulator or a real device.

    PS: in order that similar nuances do not put you in a dead end, I recommend reading the literature, where in a complex (in one place) it is told about all the nuances of the android-development. For example, B. Phillips' wonderful book "Android. Programming for Professionals" 3rd edition of 2017. This book pays a lot of attention not only to the development itself, but also to such things as working with the IDE Android Studio and reading it with you would definitely There was no problem, as in the question.

    • Thanks for the expanded object. All clear. In this case, as I understand it, the full meaning is lost in the part of Android Studio as a visual editor. After all, I even do not see about the layout on the screen. And, what's more, the editor is even misleading. If, for example, I wish to put some ImageView between two ListViews, then I will not see anything either. I’m not talking about some of my data from the array, but the dimensions are not even maintained. Components are simply not drawn. PS Thanks for the book. Already downloaded. I will study. - hubble
    • You can see the layout of the item by opening the markup of the item itself in the visual editor (you will see how one element looks like), including from Android API resources. Also, "some" ImageView between two ListViews are displayed on the markup, and the dimensions are maintained, at least for the display parameters specified in the visual editor - the visual editor is not so bad :) Problems with your layout may be problems. - pavlofff
    • In order to maintain dimensions on all the variety of android-devices, you need to use adaptive layout , and not hardcore values ​​for the sizes of widgets. Also in recent times there is a problem of "glitches" in the visual editor (nothing is displayed at the preview), an unambiguous solution of which has not yet been found and you need to wait for the fix (someone can help change the topic , someone needs an API change ), maybe you have the same problem. - pavlofff
    • If the answer helped you solve the problem, read what you need to do here, when someone answered your question and how to say "thank you" here - pavlofff