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 !!
Related
using firebase-ui and some coding I have set up my code to work like this:
1) it retrieves data from firebase (image, text and so on), then it passes them to another activity.
2) the new activity receives datas like strings and shows them.
Just to give you an idea I am looking forward to building a streaming app. What I want to do is to show an episode list via recyclerview.
What I am doing right now is a nested scroll view and a copy-paste script to pass up to 26 episodes, but this is not a really good method and I would like to have some suggestions in order to go forward in the best way and solve this problem.
this is a screenshot of the app: https://imgur.com/a/vgBnZTA I am just passing strings to the 2nd activity, then i check if it is not a null string, if it is i hide the layout, otherwise it shows, but it is just a copypaste of code. I hope i was clear enough
Thanks everyone for your support
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 have a ListActivity where the ListView is driven by a custom array adapter which has custom objects in it. The custom object is a Site.
On orientation change, my current implementation is trying to hit the database again to populate the ListView and I want to save the current ArrayAdapter then re-attach it to the ListView after the orientation change.
Whilst I wasn't keen on it, I resigned myself to the fact that I would need Site to implement Parcelable so I could then save the entire ArrayAdpter to the bundle as an array of Paracables.
I have looked at this post which does pretty much what I need to do.
However, my Site object has variables within it which are also custom objects and those objects themselves also have other objects such as DateFormat in them. I can't figure out from the post that I linked to above how to implement this so that the objects within the objects that make up part of the Site object can be included in the Parcel, since this example only deals with strings and the parcel doesn't seem to have a writeObject() method!
Are there any alternatives? (I'd love to avoid using Parcelable at all, but if I have to that's ok)
thanks
Aaron
You are using ListActivity, that means your UI is similar in both orientations ?
If yes, you can avoid the condition of recreation of activity on orientation change by adding android:configChanges="orientation|screenSize" in your manifest for this activity.
If not, then you should use a FragmentActivity and make a listview in that, and then you can use onRetainCustomNonConfigurationInstance() to return your adapter object and after configuration changes get it using getLastCustomNonConfigurationInstance()
Getting straight to the point, I'm new to this and trying to use this https://github.com/matshofman/Android-RSS-Reader-Library library to parse an rss feed and put all that into a listview. (I don't mind if you give me an alternate solution to this though. I picked this simply because it looked like it would be easier to understand and less work....)
MY problem is that I'm not sure how to do it, and when I read up on it on google it's either darn confusing or Eclipse says there's something wrong with it and gives me an error.
So :: can someone please explain to me, how I should go about doing this. I understand how to put a URL into this feed, and generally how listviews work,
but I'm getting stumped on passing the data that the library extracts from the feed and passing it into my listview. I don't have a clue how to write out java code that tells it to take data that this library passed and say, put it into this string.
I'm also confused about how a listadapter / adapter works. I think I understand how to write it, but all my past attempts have given me errors and I'm not sure what's the problem there.
It would also be nice if someone could explain how the list_layout thing works out. By that, I mean when you create a new xml file and define how one row of the listview looks, but I don't see how it gets linked up with the main xml file with a single listview.
Thanks for helping me out - it's a school project....
(btw, please be simple with the explanations. I think the main problem i'm having is that a lot of the tutorials like using very technical language, and it ends up not getting the point across to me. Even if you give me a chunk of code, and tell me all that parses my url, that's all i need.)
A ListView needs an Adapter to know what the data is and how much of the data there is. The ListView asks the adapter for a view to display a single item using the adapter's method getView(....). In this method you should inflate your view (the item) using the getLayoutInflater().inflate(..). You then get a view for which you can get the specific sub-views by using the findViewById(...) method on that view. Of each sub-view you set the value of a part of your item.
In order to avoid having to inflate a view for each and every item the ListView recycles item views whenever possible, therefore the method getView(...) receives a view, if that view is not null you can use that view instead of inflating a new view.
While reading your data, or when you have read all your data, you need to tell the adapter that the data has changed, which then tells your ListView that it needs to redisplay data. You tell your adapter by calling notifyDataSetChanged().
There is a Google I/O session on the ListView, maybe that might be interesting to watch: http://www.google.com/intl/nl/events/io/2010/sessions/world-of-listview-android.html
In you android-sdk under /samples/android-xx/ there is a sample called "XmlAdapter" which contains a RSS-feed activity. Could be a helpful alternative.
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.