Dynamic custom ListView in custom Dialog - android

I need your help, cause I'm thinking about how to resolve this problem and don't know what's the best method:
What I have:
I have a standard ImageGallery. Below this, there is a Button.
What I want:
When I press this Button, there shall be opened a List of all the images, consisting of a small image on the left and a short description in one row, all the content should be brought by an array in an extra folder.
By clicking one row, the chosen image should appear in the Gallery and the list should be closed.
What I am thinking:
is, that I have to create a custom Dialog (Alert Dialog?Binder?), started by the Button. This Dialog must be filled with a custom ListView.
What I don't know:
What components of the framework do I need for this? I have found some things with Google, but at least I'm not sure what's the most efficient way.
I saw, that somebody had created an extra activity for the Dialog, using a DialogLayout.
Someone else tried it with a builder, another one with an AlertDialog.
Furthermore, I'm confused about the combining of the ListView, ArrayAdapter, Dialog, ViewBinder, getView, Objects and so on.
Someone has an idea how to resolve this on the easiest way?

You need to do something like this:
Define an activity extending ListActivity.You can refer this tutorial how to use listactivity.
Add this activity in your manifest file with theme attribute android:theme="#android:style/Theme.Dialog" in your activity tag which will make your activity look like a dialog.
You can start this activity on your button click.
If you want some result should be returned to your calling activity then use startActivityForResult().

Related

Best control to be used as dropdown list in android

I have an activity which one of its components is a EditText. The goal of it is the following: when user clicks/taps on it, another activity is called to select some items (categories). I have implemented it using an activity that extends listactivity and using a custom adapter to paint custom rows for items.
All is ok, but I guess if using a EditText is the best option. The problem using this kind of control is that when user clicks/taps on it, the virtual keyboard appears and I do not want it to appear. If I use a TextView instead, virtual keyboard does not appear, but it is not clear for user that he have to click/tap on it to select a category (as the underscore line is not shown here as when using EditText).
So what android widget is the best to use in this scenario?
You can always use expandable list view there are many examples online that could help u to create it much more flexible than a spinner and it looks elegant and easy to use, it also show the user directly what is used for by just giving it a look and u can always customize it and play with its look and functionality.
Sounds like you are looking for a Spinner? That way you wouldn't have to load up a separate Activity to make the category selection. Otherwise, why not just use a Button? It's obviously clickable, that's for sure!

Android pop up list dialog

I want to add an dialog to my application. I want it to launch as soon as the first activity loads. But instead of having just a single message to display and having a 'yes' and 'no' button like this
I want it to display a list of message like this
If there is a tutorial that speaks on this subject I would be happy to look at it and also I would anybody by any chance know how to align these list with bulletins.
1 Create a custom dialog layout (XML file).
2 Attach the layout to Dialog.
3 Display the Dialog.
4 Done.
Tutorial here
If there is a tutorial that speaks on this subject I would be happy to look at it
Your best bet would be to start Here in the Docs. They show a great example of doing it with a Dialog.
Another option, if this can be the entire Activity since you want it to happen when if first starts, is to use a ListView for your Activity and use setChoiceMode() on it. You can find more about that in the Docs
With this second option, you can make the Activity appear as a Dialog by adding this line to your <activity> tag in the manifest.xml
android:theme="#android:style/Theme.Dialog"

Activities, Views and Dialogs in Android. Proper application structure for game

I was in the midsts of tinkering in android with the goal of trying to make this small exploration game. I actually got pretty far so far: a nice sprite system, a title screen with a main menu that is all in game code (no UI buttons or anything) that launch various activities. An activity that loads this cool map view, that when clicked on will load up another view of a more detailed "zoomed in" action part of a map. It all works pretty well but now I am left wondering how well I am going about this.
(What happens to a view when you instantiate and then move the set the context to a new view? I am guessing as long as the activity is alive all the instantiations of various views that an activity uses are still good? And in an activities onPause is when id have to save the data thats changed in these views to persist the state in the event the user quits the game etc.. ?)
I have three menu options at the start of the game. The main one is:
New Game
The new game, I launch my main map
activity that can launch three views:
First two are a loading screen for
the second, a map screen.
Third view is a more detailed action
orientated part that uses this sprite
engine I developed.
It all works pretty good as in the map view you click on a cell it tells the Calling Activity through a listener to start the detailed action view, and passes in the ID of the cell (so it knows what objects to load in the detailed view based on the cell clicked in second view). (This took me awhile to figure out but someone helped here on another question to get this.) Reference that helped me on this part here. I also used the various information here on ViewSwitcher.
I got even a yes no dialog box in the second view that asks if they really wanna goto that cell when they click on it, a yes tells the calling activity to set the new view. What helped me to get this working was this reference here. I also had to fiddle with the calls to getContext and that, I am still not 100% sure what getResources and getContext do for me.
So is it bad practice to call and load a dialog from a view? If it is, then I don't understand how if I have an event in the view that needs to pop up a dialog how I do that? Call back to the activity and let the activity handle it the dialog response and then call a method on the view for the response?
So far all this works great, I did have a bit to learn about threads too. I spawn a different thread for my MenuView (handles the detection of button clicks and responses), my CellMap view which handles the cool big map that users can click on to see the indepth view which is my SystemView view.
So basically the activity call list is like this:
Home.Activity -> ScrollMap.activity which listens to CellMap wher ethe Yes/No dialog apperas (in the view of CellMap) and if the answer is yes to the question, then the onTouchEvent starts up the SystemView view using
private CellMap.MapClickedListener onTouchEvent=
new CellMap.MapClickedListener() {
#Override
public void onMapClick(int id) {
setContentView(new SolarSystem(theContext,id));
}
};
To help anyone else, that listener had to be defined in my CellMap class. Then in the ScrollMap activity when I am about to start the CellMap I just call a method to CellMap sets the map click listener. So far this is the only way I have been able to get data from a dialog (in this case a it was clicked so set the new view) back to the calling activity. Is this proper practice?
Now my biggest question is, I have a playerObject class I want to initialize on new game event (I know how to detect that push) and that then is available to any view in any activity for the life time of the cycle. So far the game activity has just two (3 if you count the loading progress bar) views. I want to get the players name, is that another activity or view? I cannot find a decent tutorial of just how to make a simple input dialogg box that would return a string.
How do i go about passing this stuff around? After I get the players name from wherever that edit box is to be loaded, I want to set the players name in the class and pass that class instance off to another view or activity so they may get at that data. Everything I have searched on this seemed like overkill or not the right way. Whats the best way to pass this "playerClass" around so that I can access it from other views (to say display the players name in every view).
I also have my Home Activity that waits for an onClick on 3 buttons, it then launches their activity that shows the view. I realize a continue game and new game are the same activity and will just change in data loaded off the drive to restore a save game. When the new game button is clicked I would love to get the players name they want to use and of course set the member of the playerClass to this name so it persists.
Where do I call (an edit dialog is it?) the edit dialog from? (more over how do I build one that can take an okay button and input from keyboard etc). Id also like to make it pretty, maybe I could have a simple view that has one edit box in it and a nice image background (though I haven't figured out how to place the edit boxes to fit nicely matching a background i draw for it. I guess id like an edit dialog I can skin to look how i want it to and fit the look of the game).
I am actually kinda happy what I got so far its looking not to bad, just not sure about some specifics like getting user input for a name of the player. Storing that information and passing it then to other activities and views.
Is it better to have one GameMain activity, and a ton of views:
Map view
Character sheet view
inventory view etc etc?
Or Should there be diff activities in there somewhere as well?
You've written a lot here, so I'm go gonna go ahead and answer the questions I think you're asking.
First, how can one share information between activities and views? If you're just sharing it between views in a single activity, store it in the instance of the Activity subclass.
Sharing between activities requires a little bit more. Instead of using an instance of the default Application class, you can create a subclass of Application and use that instead. Put your data in fields of that subclass. To tell your app to use your subclass, modify the app manifest like so:
<application
....
android:name=".YourAppClassNameHere">
....
</application>
As for getting user input, the simple answer is use the built-in EditText view. since you seem to want to give your game a more "custom" style, though, you may need to go about creating your own editable textbox. That and buttons should allow for most sorts of basic user input.
Now, good practice vis-a-vis activities and views. I'm not aware of a standard for this, but when designing I generally try to think of activities as more conceptually separate elements, whereas views are conceptually interwoven. the line between the two is dependent, in part, on the scope of the app; an app with a narrow focus can afford to break more actions down into different activities than can one with a much broader focus.
Your "GameMain" example is a bit on the fence, but I think you've made the right choice: the activity is "playing the game," as opposed to a menu or high-scores table, and the views present different aspects of the game being played.

Add a view/activity on top of a ListView [Android]

I want to have a view with several choices when I click an element of my ListView. I was thinking of implementing an AlertDialog but as I need more than 3 options it is not possible...
I also thought of putting my ListView in a FrameLayout and have an view with a gone visibility that I would turn visible at the click and update the content but I don't know If it's a good idea.
I could do with some advice,
Thanks for any idea.
You can use ContextMenu, if dialog works fine for you. If you don't want the dialog then use PopupWindow.
You could use ContextMenu
This tutorial may help.
Edit based on the comment:
Hmmm.. Since you want more than 3 options and icons in the menu that's displayed when a item is clicked; you could set an onclicklistener for an item in the list and on clicking switch to an Activity that extends a BaseAdapter along with your own custom layout.
I personally don't recommend this as it could complicate things quite a bit. Context menu is quite straightforward and way to go.
You can create another activity, and give it the dialog theme:
<activity android:theme="#android:style/Theme.Dialog">
This causes it to look like an AlertDialog, but you have full control over what it looks like.
Note that when I used this previously it was rather slow, at least in the emulator though.

Possible to use the ListPreference modal view in a ListActivity?

I am trying to put together a modal box with a scrollable list of checkable items and an OK and Cancel button at the bottom for the user to select filters from. It seems the simplest way to do things like this in Android is to reuse API components (widgets, layouts, etc) and the closest one I can find to this looks to be the ListPreference, which basically does exactly what I want (I can even work with storing the data in SharedPreferences).
The problem is that I'm not launching this modal box from a PreferenceActivity, but rather will be launching it from either of two activities: a ListActivity and a MapActivity. If a ListPreference would be possible here, that'd be really convenient, but otherwise any help getting me in the right direction would be great.
Thanks!
Nick
Try an AlertDialog, supplying it with your ListAdapter via AlertDialog.Builder.

Categories

Resources