Android: Renaming gui elements vs. new layout - android

I'm new into android and i'm dealing with the following problem. I need to create a button which groups another two buttons of similar features (sort of submenu). So let's say we have a button called "search", by clicking on it the search button should disappear and the two buttons (e.g. "google" and "bing") should be seen on the screen.
So, my idea was to manage all three buttons programmatically in the same layout instead of creating a new (temp)layout just to show and handle the two buttons. Like a state machine. More precisely it would be like this:
We press on the "search" button.
onClick(View) determines wheter we are on the main screen (mode=mainmenu), renames the search button to "google" and creates the second button named "bing", or (mode=submenu) then call the function of the button due to the search button is already renamed to "google"...
By pressing the back button onBackPressed() checks if we are in the submenu (mode=submenu) then hide the "bing" button and rename "google" to "search", otherwise we are in the main menu (mode=mainmenu), finish the activity.
Does this make sense at all? Besides this will produce lots of code with rising count of buttons and (sub)menus and worse maintainability for further changes.
Thanks!
P.S. Sorry if my english sucks (not my native language) ;-)

That's too much code and too much debugging will be needed, so I think, a better way is just creating a new layout.

Well if you have performance issues or expecting performance issues can arise (due to complexity of you GUI) then may be this make sense. But if not, code simplicity is more important than slight increase in performance.

You can create an button that remain invisible(gone, to be exact) until the "search" button is pressed, and rename the original search button. It works, and it will be easier to implement if you set up layout in xml. It also give you a preview that shows what it looks like. To show widget programmatically will have code that hard to maintain.
However, the design that change button text is not a good design. First, when the "search" is pressed, changing its text is very confusing. I personally suggest you to pop-out a selection dialog. Or just show both search button at first place, unless you really do not have place for two button.

Related

Customizing AlertDialog.Builder with multiple Buttons and EditTexts programmatically

The issue I've been running into is creating an AlertDialog popup that includes multiple EditTexts and Buttons, while also including the usual positive and negative buttons. With an additional '+' Button that would create another 'set' of EditTexts and Buttons below the previous one.
A visual example.
I would also like to do this programmatically, if possible. The issue I've been running into is setView(), it seems like that method is meant to be used for only one sort of Button, EditText, or otherwise to show on the screen. But as I need more than one, and calling that method more than once just overrides the previous call, I've become stuck. The only thing I can find that might be it is ViewGroups but I haven't been able to find a way to work with it.
Any information on this would be immensely helpful!

UI design of a ListView editor

I need some way to edit an item in my multi-line ListView - and it's just two text fields that need editing.
What would be the best way, design-wise, go about this? I feel that a whole new activity would waste too much screen space and look off, yet just a popup with the two fields and some confirm button might look off as well.
It's pretty subjective as to what's the best design for this, especially without knowing more about your specific use, however there are definitely a few possibilities that come to mind.
The new activity option that you noted is actually quite standard. You can see a similar paradigm used in Gmail, Google Talk, Messaging, etc. If your text fields expect to have something like a single word in each though, I can understand how that might feel like a waste of space to create a new activity. I wouldn't necessarily rule it out though; you can probably play around with styling to make it feel less empty (include labels, short descriptions, etc.). Also consider that most users nowadays have soft keyboards. That can take up a significant amount of space and make the view feel less empty.
The popup option seems less standard, but again if you styled it correctly I could see it working OK. What don't you like about this option?
Another option is to do a multi-pane layout of sorts which is far less common for a phone-sized layout but not out of the question. You could have a pane with two text boxes which is for the current item above your list view and have the contents change when you select an item in the list view. This is also a less standard UI.
You could also have an alternate view actually within the list item. In addition to your current (I'm assuming) two TextViews, you could have two EditTexts and maybe an OK and cancel button that are hidden. The visibility of all of these views would be toggled when you select the item.
There are more options too, I'm sure, but hopefully this will give you a little to think about at least.
I would use a separate activity for several reasons:
1) It's what users would expect. I can't recall any apps that use a pop up to edit contents of a listview
2) It'll be much easier to manage state in a separate activity e.g. when a user starts to enter some text and then gets interrupted by a call or email notification etc
3) If you're editing text then the keyboard wil take up most of the screen so you're activity won't look sparse.
you need to update in list view and add more items in list view???????

Component to add arbitrary number of input fields?

I apologize if I'm just missing the obvious. I'm fairly new to Android development, and while I searched for this particular topic, I wasn't exactly sure what to look for (in terms of a "name").
In an application I'm writing, I have a section where the user can enter the names of players. However, this can range anywhere from 1 to whatever, no limit. However, I'm not sure what the best approach for this kind of feature is, or if there's a component that already does something like it.
Basically, the functionality I'm looking for is similar to what you can see in the Edit Contact screen of the phone book; for the phone numbers and email addresses, you can push a little plus button to add a new number/address, or hit the little minus button to remove a number/address.
I can think of several ways to potentially implement this, but in the end I think wrapping it in a custom component would be best (so that you could call "Get Players" and have it return a list of strings by going through each of the inputs and getting the values).
Am I just overthinking this? Is there a component that does that already? Is there some example code that demonstrates a good way to do this?
Thanks!
Could you just use ListView and add a menu with a "Add Players" option? You could customize the list view to have a little checkbox, for example, and then begin the game by pressing the menu ... or add new players dynamically by pressing another menu button.
After playing around with some ideas, I came across a solution that I think will suit what I'm doing. I created a custom component extending LinearLayout. As part of the creation of the component, it creates a row that says "Add new..." with a plus-sign button. Pressing the plus sign button then creates a new row containing an EditText and a minus-button which will remove the row.
I then created a method for this component called getTexts() which returns a List that has all the non-empty Text values from all the components. Testing it in a dummy app, it seemed to work fine.
I think I need to make tweaks to make it more robust (like the ability to add rows programatically, listeners to alert other components when a row is added/removed, and the ability to set the individual EditText values, for instance), but this functions as I imagined.

Android app, showing a keyboard

I recently wrote my first app for android, and I created a listview for selecting an element from a list of about 500 items. Since it's basically the default listview, it's searchable, and I can bring up the onscreen keyboard by holding down the menu button, but I was wondering if there was a way to bring up the keyboard automatically (and not make it freak out if the phone has a physical keyboard). Does anyone know how I can do this? I've been searching around and haven't found anything.
Add this to your xml activity list definition (AndroidManifest.xml)
android:windowSoftInputMode="stateAlwaysVisible|adjustResize"
Maybe not exactly what you want, nevertheless; you could add a EditText above your list. When this EditText gets focus (which it will by default when you show your activity, presuming it's the first GUI component on the layout) it will also automatically trigger the software keyboard.
The neat thing of this approach is that it gets even more intuitive for the user that he or she can actually search the list by entering a search criteria.

Android with multiple content view at same time?

I'm very new to android and I am wondering how I can have 2 windows displaying content at the same time.
Here is an example:
I have a HorizontalScrollView at the bottom of the screen which houses the buttons for a menu. Above it, I would like a window(like a JFrame) that I can change depending on which button from the menu was pressed. The ScrollView menu must remain unchanged an exist as a separate entity(if you know what I mean).
How can I go about doing this? I don't want to have to draw the menu every time a user click a button and a new page is displayed. I have a feeling it has something to do with intents and Activities, but I'm not sure.
Hope someone can help me out.
Thanks.
I'm very new to android and I am wondering how I can have 2 windows displaying content at the same time.
Interpreting you literally, you can't, but that's because "window" does not mean what you think it does.
Here is an example: I have a HorizontalScrollView at the bottom of the screen which houses the buttons for a menu.
Get rid of it and replace it with an options menu, so your application blends in with the platform.
Above it, I would like a window(like a JFrame) that I can change depending on which button from the menu was pressed. The ScrollView menu must remain unchanged an exist as a separate entity(if you know what I mean). How can I go about doing this?
Option #1: Get rid of the HorizontalScrollView, use an options menu, and use separate activities for each "window"
Option #2: Use a ViewFlipper, with one child of the ViewFlipper for each "window".
Of the two, Option #1 will generally be much better, for memory management, state management, code complexity, and UI design.
Could TabLayout be your answer :
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

Categories

Resources