How to create a large selection screen? - java

My app tracks how players at a pokertable play. I give my users the option to save up to 50 players stats in the form of a 'Player' object stored inside a JSON array within sharedPreferences. Allowing the user a way of selecting and loading one of these players has proven difficult.
An alertDialog seems to small, a new activity seems a bit overboard for what is essentially just a large menu and I fear passing my objects to it will prove difficult. A viewFlipper sounds interesting but I've no idea whether it's suitable.
How should I go about doing this? Filling the screen with dozens of buttons is really all I wish to do.

I agree that creating a new activity for this would be an overkill. One way to address this would be to have a GridView populated with your "buttons" - and the user would select one from the grid by clicking it. The question is where/how to display this grid.
ViewFlipper is a nice option in my opinion. The way you would go about it is place your existing layout inside the view flipper, then put the GridView into the ViewFlipper after your existing layout:
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/flipper">
<LinearLayout ...>
<!-- this is where your main layout goes -->
</LinearLayout>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/player_select"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ViewFlipper>
Then in your activity set up the Adapter for your grid view and the OnItemClickListener - to do something when one item is clicked. Finally somewhere (either in the main layout or in the options menu or elsewhere) provide something to display this grid view. In the handler code for that action you'd have something like
ViewFlipper flip = (ViewFlipper)flip.findViewById(R.id.flipper);
flip.showNext();
This would effectively hide your main layout and show the grid instead. And at the end of your OnItemClickListener you'll have
ViewFlipper flip = (ViewFlipper)flip.findViewById(R.id.flipper);
flip.showPrevious();
This would hide the grid view and navigate back to your main layout. Feel free to add any animation you like for the transition (e.g. 3G flip animation looks particularly nice).

Try an AutoCompleteTextView. Start typing one of the names, and a list of all possible matches pops up.
Screenshot from Google's tutorial:

I went with a ListView. It combines the filtering and tidyness of the autocomplete yet displays the names so users don't have to remember them like the ViewFlipper solution.
Thanks for both answers, they are both good solutions that helped me come to the solution I needed which combines the two.
The autocomplete had the advantage of searching so I could extend the number of players a user can save to my hearts content, it also looked neat but could not easily see the whole list which for poker players was necessary as the names you give when titling your notes are rarely your fellow players name but rather off the cuff nicknames based on their appearance/playing style. Hence using autocomplete the user will have to remember the nicknames they gave which over 50 players and potentially months apart would prove tricky.
Alek Gs solution would avoid that problem but would not be suited large numbers of names or long names for that matter as the buttons would be off fixed sizes.

Related

Android Best Practice: Dynamically adding buttons to a ViewPager or Pre-Instantiating Them?

So I have a question about best practice for dynamically creating and sizing buttons within a ViewPager, based on a changing external state.
Essentially, I have a scrolling view and I want my ViewPager to contain a number of buttons of a specific size and count depending on what part of the scrolling view is currently visible.
My question is about deciding the best implementation of this feature, I see two options: would it be simpler to
Constantly create and scale new buttons whenever the scrolling view moves
Make the viewpager itself contain a scrollview and fill it with all of the pre-scaled buttons on app startup. Then, whenever the user scrolls the main scrollview the viewpager's scrollview (which contains the buttons) will scale programatically
Any ideas on which would be the simpler and more robust system?
Not much of an answer but I will leave a comment for ya! Basically you can do it either way, both aren't to difficult to accomplish, however I would probably go the dynamic route because it will always scale correctly. Doing a set amount will only work until devices become larger, or if you are targeting tablets or tvs then it will start to become extremely messy in the xml file for the layout. Dynamically adding also gives you far more control and saves time later on, you can simply change a number and have 100 more then going through and manually adding even 10. Hope this helps!

Two Separate Scrollable Fragments on the Same View - Android

I'm trying to create a basic UI for a simple Temperature Conversion app (new to android developing), and I can't figure out how to create a SINGLE page with two SEPARATE scrollable view pagers, one occupying the top half and the other occupying the bottom one.
I am using Eclipse. Feel free to ask for any other information required for your answer.
This is a rough drawing of what the layout should look like.
I'm trying to create a basic UI for a simple Temperature Conversion app
I do not know why a temperature conversion app would need one ViewPager, let alone two in the same activity at the same time.
I can't figure out how to create a SINGLE page with two SEPARATE scrollable view pagers, one occupying the top half and the other occupying the bottom one
In terms of the ViewPagers themselves, use a LinearLayout or something to vertically stack them.
Your bigger headache will come with the PagerAdapter implementations. At least one of these will have to be something other than FragmentPagerAdapter or FragmentStatePagerAdapter. Those implementations assume that they are the only such adapter for your activity, and I would expect that having two will cause collisions.

Possible implementation of game screen concept for an android game

I want to develop an android app, but I'm still not that great at using xml or the eclipse wysiwyg editor to make scalable and robust interfaces!
Below is a quick concept I drew up on word of what my main game screen will consist of:
I'm currently thinking a vertical linear frame first, with a frame that doesn't change for my important stats etc., then a frame in the middle which is switched by the buttons, but I'm stuck on how to implement this.
For the centre button screen, the map screen, I am hoping to add an image of a map which can be moved around, and somehow attach invisible button objects to points in this picture, maybe with an array of squares or something?
I understand this is a pretty open question and might be difficult to answer, but if you think you can help in anyway please do.
Thanks!
There is a log of possibilities, but you can use a LinearLayout with android:orientation="vertical" and include your stats in top. For the changing screens with buttons you can use a FragmentTabHost and create different Fragment for each of your views.
Check this example with a implementation.
Regarding the map, I think the easiest option is to use Google Maps Android API v2. Here is a example to use the maps v2 and a example of how to add markers to the map.

View different images depending on what item in my list view I click

I'm fairly new to Android programming and I've got this project I need to finish and I'm currently stuck.
I've got a standard listview in a Menu class with an array containing around 20 different elements. So what I want to do is load images in an imageview depending on which item in the listview I click, and since I'm a beginner the only idea I had was to make a new activity for each imageview which seems like a pretty bad way to do it since I'd need about 20-30 new activities..
To sum things up what I want is:
Code for making ONE activity that will display a different image depending on which item in the listview I click, probably pretty basic coding I want as simple solution as possible.
If possible I'm also looking for a solution that includes an SQLite database that stores the URL of an image and then display it in a single activity, also depending on which item I press in my current listview.
(I hope you understand my needs, and if you need I can also post my current code for the Menu class if it helps you help me) Or you can just show me a different way to make this work, I appreciate every answer! Thanks in advance!
NOTE
And please keep in mind, I'm a noob at Java and Android so keep it rather simple or at least explain what you do.
When you click on a list item, display the image in another view in the same layout, unless you want the image to take up the entire screen real estate. If you want it in the entire screen, go to a new Activity by sending the activity an Intent.
Activities are the "controller" of your application. They interact with the visible UI and the input from the user. You don't need a separate activity for each image, just an activity that's associated with a "place" in the UI (an ImageView) where you'll display the image.
I'd start by adding the images as resources under res/drawable before going on to databases.
You are going to have to do most of this yourself. There really isn't any substitute for taking the time to learn Java and Android. There are several tutorials and Android University classes under the Resources tab in the Developers Guide; I suggest you do all of them.

Android Spinner - How to make dropdown view transparent?

I have a custom spinner dropdown xml file in /res/layout/:
spinner_view_dropdown.xml:
<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/spinner_item_dropdown"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
style="#style/spinner_item_dropdown" />
I'm setting the spinner dropdown via java:
// "Spinner", aka breadcrumbs
Spinner spin = (Spinner) findViewById(R.id.breadcrumb_dropdown);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.breadcrumb, R.layout.spinner_view);
adapter.setDropDownViewResource(R.layout.spinner_view_dropdown);
spin.setAdapter(adapter);
// /"Spinner"
Unfortunately, a white background still exists on the spinner popup regardless if I set the background to transparent.
How do I fix this?
You can override the style for the dropdown, and the dropdown item by using a Theme in your app that inherits from one of the Android themes, then override the
android:dropDownSpinnerStyle, or android:spinnerDropDownItemStyle, and even the android:dropDownListViewStyle attribute of the theme, pointing to your own custom style instead of the Android style that is defined in their theme. I created a fully customized spinner this way, with a transparent button AND dropdown. I even got rid of the dropdown list dividers, and set my own spacing for the dropdown items when I built the tablet app for Fandango (take a look at the sort movies spinner on the main page of the app).
Everything in Android is customizable, you just have to know where to look. ;-)
Try setting on the spinner this:
android:popupBackground="#android:color/transparent"
The layout you're defining is only used for an entry of your drop-down, not the drop-down itself. So setting the background to transparent won't have any effect on its background. But even if it would, setting the background to transparent would still have no effect, because a TextView (actually I believe any view) has a transparent background by default.
That being said, the right question would be: can you provide a custom layout for an entry's parent view (which is probably a List)? As far as I know, the answer is no, unfortunately.
Try
android:cacheColorHint="#00000000"
to get transparency.
I dont know if it works for you but there is a post
http://android-developers.blogspot.com/2009/01/why-is-my-list-black-android.html
that explains why the moving parts of a list appear in the background color.
Maybe its the same issue with your spinner.
It's a bug in 1.5 I think, see here
http://www.symsource.com/index.php?view=article&id=418&option=com_content&format=pdf
Run it in a 1.6 emulator or device, does it still stay white?
I actually came here looking for an approach to this, I suspect this may involve manually writing to the canvas or something like that.
Any ideas.
P.S. Accidentally posted when I thought I was logged in, anyone know how to get rid of the anonymous comment? Maybe an admin could fix this?

Categories