Reputation: 386
everybody
Recently I have use ADT to develop the android 2.2 program. The program run correctly in the simulator, but it meet a strange problem when it run in the real machine.
I use BaseAdapter to create a MenuAdapter, it will load the custom class called ViewHolder. Both the custom class and MenuAdapter is similar to any sample about BaseAdapter: ViewHolder only have two variable text and image, without any codes. MenuAdapter load the Menu layout that contain a TextView. It will assign the text variable in the TextView and load it as Alert Dialog repeatly.
Then I create array carry the following variable:
public String[] menuOptions={"Browser", "Google Map", "Camera", "Gallery", "Media Player", "Cancel", "Exit"};
After then, I use the AlertDialog.Builder().setAdapter() to create the BaseAdapter object and load the array in. The Alert Dialog carry on the data set. But it output this:
Browser, Google Map, Camera, Gallery, Media Player, Cancel, Browser
The last item change in random, I load the Alert Dialog again and it can turn out this:
Browser, Google Map, Camera, Gallery, Media Player, Cancel, Google Map
Browser, Google Map, Camera, Gallery, Media Player, Cancel, Gallery
no Exit...
So I want to know, what is going on? Why it does not load all the data? When I meet this problem, I try to reduce the Array to
public String[] menuOptions={"Browser", "Google Map", "Camera", "Gallery", "Media Player", "Cancel"};
It display correctly:
Browser, Google Map, Camera, Gallery, Media Player, Cancel
There is no numeric setting about the array loading in the MenuAdapter Class, so I don't understand about this.
Upvotes: 1
Views: 228
Reputation: 386
I have found the answer.
The Dialog Alert display in wrong data because some of the data is displayed outside the screen. Dialog alert will display them in scroll-y style (if you know what HTML and CSS is then you will know what I mean).
The data that hides in the scroll-y style will display in random......for example, my last item "Exit" is hide under the screen when I load in, I drag down the screen to review, it will display the last data in random, not "Exit".
I solve it in changing the line height of each items, make them shorter, make them display in one screen without scroll-y style and it will display the data correctly.
I don't know if it is system bug or not.
Upvotes: 1