What I want to do is quite simple : to display a dialog form containing an EditText in which the user can specify a message.
So far, I have tried to use the DialogFragmentclass. With the explanations found in the developer's guide, I have been able to display an alert dialog box showing a message. But I can't figure out how neither to change the layout of the AlertDialog created to use an XML file of my own or to replace the AlertDialog with a customized class extending the View class for instance.
Am I missing something? Or am I completely on the wrong way?
Thanks in advance for the time you will spend trying to help me.
You absolutely can do this, even using an AlertDialog!
You just have to set a custom layout for the dialog, in AlertDialog you would use the setView method and if you want to use a more generic dialog you can use the setContentView method.
You can take a look at http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog for some more information and an example.
The example in the link provided is contrived without question but it is meant as a stepping stone towards a goal similar to what you are trying to accomplish.
There is a similar question/answer that might be of use to you.
Related
Despite its not best UX. I wonder what is the best solution to start several different Activity(Dialog) with different callback implementation. I assume starting each dialog needs to be from static fabric method with context.startactivity(dialog1). Each dialog looks exactly the same besides some title and message but callback for ok and cancel buttons are different. I want to separate implementation of dialog callbacks(ok, cancel) from generic dialog behavior. What if I can't pass actions while starting activity from static method, I don't find Bundle to fit this case.
How about this, create an enum for the dialogs.
Based on the enum you can either have the values for everything be in the enum itself or switch on the enum in your code at the appropriate places.
recommend creating different click listeners for the yes and no buttons.
In those click listeners you can switch(enum) and for each case have the specific business logic. OR create different click listeners and use a factory that will allocate the listeners based on the enum.
either solution works depending on how you want to code it. They both have their own pros and cons.
There is an AlertDialog.Builder class that you may be able to use depending on what your dialogs look like. There is also the dialogfragment class that you can extend to help out with the dialogs.
if you want to show the users several dialogs you will need some sort of queue that you populate with all the dialogs that you want to show and then show them one after another, IMHO, use different views and just replace the view in an activity so you can slide it in or animate it in somehow.
You can make them look like cards and then just change the text inbetween that way switching on the clicklisteners based on the type of the current view will be easy and you can even have the enums provide the views using the R.layout.layout_name as a value in the enum.
I know that is a lot and maybe some of it is unclear, Please ask questions and i will do my best to respond in a timely manner.
I am working on making a custom keyboard using this guide and it seems to work except when I try to use it for an EditText in an AlertDialog. I've tried setting flags as suggested in this answer but that does not seem to make a difference. Any ideas on how to make it show correctly?
In my android app, I want to make a dialog box, the kind of one you get from alertbuilders, where you get access to set positive/neutral/negative button click, but I also want to use the .setcustomview() to load the content with my xml file.
Does android have a way to do this? I want to avoid making those buttons...
Thanks
I don't see a setcustomview() method for the AlertDialog.Builder class, but I do see a setView() method, if that's what you mean. :)
From my experience, using setView() will allow you to set your custom XML layout (though you will still need to inflate it first) without requiring you to recreate / add buttons to your layout. You just need to call the setXxxButton() methods before you build.
I have to implement an EditText search field that, when the User is typing, it fetches suggestions from the internet and shows them in a drop-down menu.
I have read some doc stuff, and I've seen that there is AutoCompleteTextView class that realizes just this function, after setting a generic ArrayAdapter.
But in all the examples I've seen, the ArrayAdapter was filled with a static String array.
So I was thinking:
Is it simpler to use an EditText box and handle all the UI stuff on my own, or to use AutoCompleteTextView with an Adapter? In that case, will it correctly handle the changes of the suggestions array?
I would suggest to go ahead and use the autocomplete with Adapter option. You can easily do what you want by first taking the response from the net and then using it in a handler for onTextChanged. Implementing from scratch the GUI with edittext would be cubersome as well as time-consuming !!
I have created a custom dialog box extending the DialogFragment class. As stated in the Androïd developer's guide, I have set the style and theme of my dialog. I use the DialogFragment.STYLE_NORMAL style, which, I suppose, authorizes to set a title to the box. This seems confirmed by the fact that a style called DialogFragment.STYLE_NO_TITLE exists.
The problem is I can't find any function to set this title.
How can I do?
Thanks in advance for the time you will spend trying to help me.
Just call getDialog().setTitle("My Dialog Title") to set the title
I think you could call getDialog() to get the contained Dialog instance, then call setTitle on that with the required title.
A bit of a guess, since I'm not an Android developer.