Alternative to using a list of Fragments? - java

I want to have a list of pre-fabricated templates, where each item in the list has a first name, last name, and buttons that relate to that item in the list (Delete, rename, extra info, etc.) what would be the best way to do this?
The closest thing I can think of that would be similar would be something like a twitter feed: http://www.androidguys.com/wp-content/uploads/2013/12/Twitter-Feed.png
Where each "post" is based on a standard template, and database info is plugged into it, as well as buttons that belong to that post.
Currently I have it so my app uses a list of fragments, but that seems really hacked together and takes a lot of time to load more than a few of them.
Is there an alternative? I think I read somewhere of someone recommending another person to create a custom viewadapter, but as I am still somewhat new to android, I'm not sure if this is the best way to do it.

Related

JavaFX outlook like calendar

Now I know that this question has been asked already, but the solution there didn't help me much
As the title suggests, I am looking for a way to implement an Outlook like calendar into my JavaFX application.
I already tried out fullcalendar, but I didn't manage to start the jQueries, which are needed. I tried a lot of methods, but they either aren't working or I'm too dumb to implement it correctly
I also tried jfxtras agenda, I really like the controls and the look of it, unfortunately I'm a rather inexperienced programmer and therefore I'm not really capable of saving these entries
So, if someone could show me an easy - to - implement calendar or a guide to either fullcalendar or jfxtras agenda, I would be very grateful
Thanks in advance
EDIT:
Here are the links,
1) Fullcalendar How to add JQuery onto JavaFx WebView
2) Similar question: Outlook like calendar control in JavaFX 2.0+
Well, JFXtras has a samples in which you can add appointments to Agenda. You can download it from the jfxtras.org website and play with it.
The source code ain't that complex (all you need to do is implement an add appointment callback, see line 44.), but you will need to code yourself. Agenda only does the displaying of the appointments, it is your responsibility to store and retrieve them from your domain model.
https://github.com/JFXtras/jfxtras-labs-samples/blob/8.0/src/main/java/jfxtras/samples/controls/agenda/AgendaSample1.java
Basically what you need to do is:
implement the localDateTimeRangeCallback and set the appointment collection in that method with data from your domain
implement newAppointmentCallback and store new appointments in your domain
monitor the appointments collection for removals, and remove the corresponding appointments in your domain.

How/Where to implement onItemClick handlers with several fragments

I am currently a student taking a Mobile Device Applications development class and am getting stuck on my final project, an Address Book style app. I have used the example from our book (Dietel's Android for Programmers An App-Driver Approach, Volume 1, Second Edition) as the basis and have been editing code from there. The biggest thing I want to change/enable is to allow the user to select different fields within the contact (address, email, etc) and pass an Intent that will open Maps when address is selected, eMail when email is selected and so on. Where I am lost is where to place my listener and declare it. Our book and subsequent searches are not really clearing this up at all. I understand the onItemClick call, but am not sure where to place it, within MainActivity.java or the DetailsFragment.java, which is all the code to handle anything that happens when the contact is open and displayed. I feel like I can put it all within the DetailsFragment.java but have a nagging suspicion that I am missing something. I have not had the time to edit and test this yet as I am actually heading out for work in a minute but I thought I could maybe get a better understanding or maybe even better links to read to learn from as my Google search doesnt seem to address what I am looking for. Also, not sure if it matters or not, but I am not using a ListView at all and everything I find tries to force a ListView use. Thank you guys for your help/consideration and time.

Notify when web content change

Im new to java and working on a simple application that monitor an url and notify me when a table is updated whit new items. Looking at the entire page will not work as there are commercials that change all the time and they would give false positives.
My thought was to fetch the url line by line looking for the elements. For each element I will check to see if the element is already in an arraylist. If not the element is added to the arraylist and a notification is send.
What I need support with is not the exact code but advice if this would be a good approach and if I should store the elements in an array list or if I should use a file instead as there are 2 lines of text in each element.
Also It would be good to get recomandation on what methods and libs there would be good to look at.
Thanks in advance
Sebastian
To check the site it'd probably be more stable to parse the HTML and work with an object representation of the DOM. I've never had to do this but in a question regarding how to do this another user suggested using JTidy, maybe you could have a look at that.
As for storing the information (what you currently do in your ArrayList): this really depends on what you use your application for. If you only want to be notified of changes that occur during the runtime of your program this is perfectly fine. If you want to have the information persist you should find a way to store the information in the file system or database.

Implementing auto completion in Java

I was working on creating a weather application in Java using Weather Underground and I found that it does have data for some cities.
Initially, I was planning on using GeopIP to get the user's location automatically but since the support for cities is limited I decided to let the user choose the city every time the program starts.
I want the user to be able to choose a city from one that is supported by Weather Underground. The user will enter the name and as he/she enters the name, the possible locations will be displayed in a way similar to the one shown in the picture.
My question is:
How do I implement this search feature ?
My initial guess was to create a Vector containing all the names of the cities and then use brute force to find the match and display in a JPopup or a JWindow containing a JList but I guess there has to be a better method
Rephrase:
What I do not understand is WHAT INFO do I keep in the data structure I must use ? Should I manually create a list of cities that Weather Underground supports or is there another way to do it ?
Take a look at the Trie data structure (also known as digital tree or prefix tree). Autocompletion is one of the most common examples of it's usefulness.
The following article has a nice an very approachable explanation:
Roll your own autocomplete solution using Tries.
if you google autosuggestcombobox you will get some interesting results:
This one is written in JavaFX - I have used and extended it myself already. It is quite useful. What you get "for free" with JavaFX: a context menu with right-mouse click which is auto-generated containing some of the usual "stuff", like cut, copy & paste and even undo! So, I can recommend that solution. To get into JavaFX isn't so hard - and I think it is much easier to learn than Swing - and looks so much cooler! However this implementation has some drawbacks - especially when the layout is not left-aligned, because it is simply a text field on top of a combobox.
OK - but if you want to stick to Swing - you could probably use this one. I haven't used that myself, but the code looks quite straightforward and pretty clean - cleaner than the implementation for JavaFX I must admit (but that had some nice features). So - maybe you try - and extend it? It is built simply on JComboBox.

Fast search in java swing applications?

I'm wandering myself what component is the best for displaying fast search results in swing. I want to create something like this, make a text field where user can enter some text, during his entering I'll improve in back end fast search on database, and I want to show data bellow the text box, and he will be able to browse the results and on pres enter result will be displayed in table. So my question is is there any component which already have this logic for displaying?
Or is it's not, what is the best way to implement that.
This search will be something what ajax gives me on web, same logic same look and feel, if it's possible on desktop application.
Are you looking for something like an AutoComplete component for Java Swing?
SwingX has such a component. See here for the JavaDoc. It has a lot of utility methods to do various things, i.e. auto-completing a text box from the contents of a JList.
I strongly, strongly recommend that you take a look at Glazed Lists - this is one of the finer open source Java libraries out there, and it makes the bulk of what you are asking about super easy.
You will have to first attach a listener to the JTextFields Document to be notified whenever the user types in the field (or changes it).
From there, you can fire off any server-side code you need. The results of that can be used to update a listbox.
A few things to keep in mind:
The code to do the search against the backend must be in another thread
The code that updates the list box should update the list box's model
You will need to manage all your backend search results so that you only update the listbox with the most recent result (e.g. user types 'A', backenf searches for that. Meanwhile, user has typed 'C', kicking off a backend search for 'AC'. You need to ensure the results from the 'A' search dont' make it to the listbox if the 'AC' search results are available).
Use Hibernate Search.
The SwingHack (http://oreilly.com/catalog/9780596009076/) book has an example of this.
In the interest of killing two birds with one stone: have a separate indexing thread. This will:
Improve the speed of searches whenever they are executed.
Improve the responsiveness of the UI since indexing is happening in a separate thread.
Of course, exactly how you perform the indexing will vary widely depending on your particular application. Here is a good place to start researching: Search Indexing. And please, ignore the reference to Web 3.0 [sic].
It is possible of course. It is simple too. For drop down list of terms just use popup menu. This is simple. The background processing of entered text is simple too. Enjoy!

Categories

Resources