I have to represent tree data having number of levels in android app. As per native API, using list view we can provide only two levels. It is also reasonable because using fat fingers we can't expand or shrink tree properly.
So is there any alternative way to represent this tree like data?
Can you not 'drill-down' by clicking on the second level. The second level then becomes the first level (visually) and you then add in the third level as the second level (visually). You will need a 'back' button of some sort to move back up.
Or do you need to show the whole tree at once? What is in your tree? Just labels/names, or multiple data values per node?
Also, a long shot - but for ideas (if you like writing your own components):
http://www.cs.umd.edu/hcil/treemap-history/
Related
I need to display a Recyclerview that can have any amount of subheadings. Sadly I only found solutions that support a depth of one. This isn't enough for my case.
I could have something like this:
Heading 1
Subheading 1
Subsubheading 1
Subsubsubheading 1
Subheading 2
Heading 2
...
You get the idea. Futhermore, it would also be quite useful if the user can expand these headings and their content like in MS Word. How does one achieve this behaviour (if possible without external libraries)? Thank your for you support!
I ended up using a combination of the approach from user3170251 and my own. Because my headers are from different models I used an interface and all models implement that interface.
The recyclerview only gets a list of objects that implement the interface. By checking the type of the current element it knows whether it is a read-only header or a normal element with special on-click functions. Now, to have some sort of hierarchy you need to store the depth in the model itself. So the data hierarchy that the recyclerview sees is still a flat list, but by saving the depth in the model itself I can give headers with a deeper depth a smaller font size.
The answer from Anshul Aggarwal on Is there an addHeaderView equivalent for RecyclerView? really helped me out.
Please deal with this naive question.
Objective is to create a UI and dynamically be able to change the basic workflows, add another option, add another steps etc.
As an example, one simple workflow could be as following:
What's the age of 'X'? TEXT_BOX
if(age>18) proceed to step 2.
else, go to next page (let's say, same processing happens again with different value of X).
What does 'X do?
a. Job
b. Business
Submit (Go to next 'X').
I wanted to keep this workflow in XML as complete tree (all branches of if/else-if/else) and pass it on UI for rendering. Some of the sub-trees will be populated as per action performed in previous step.
This way, small modifications or workflow changes will not require any code changes.
Other option is to use JSON and pass it directly (rather than converting XML to JSON and passing) but it will be loosely coupled and could be difficult to manage in future.
Is there any clearcut benefit I should think of before choosing any of them?
Will any of them provide any extra benefit in the problem I am trying to solve?
Thanks,
It is possible to mimic the structure that you plan to have in an XML, as a json string, without any hurdles as far as I think of. (If you think of any hurdles please point out, I might help you out with idea to handle that).
json will for sure save you lots of bandwith if the data you are planning to send is large. This will inturn also reduce the roundtrip time and make your application more responsive.
Im in the process of teaching myself data structures and I am currently working on a binary search tree. I was curious how you would sort the tree if you had identical data. For example say that my data consists of [4,6,2,8,4,5,7,3].
I set 4 as the root element
put 6 to the right of it
put 2 to the left of 4
put 8 to the right of 6
Then I get to 4 where do I put it since 4=4? To the left or the right?
Option #1
Option #2
Are either one of these correct or are they both wrong? If they are both wrong could you show me how they should be sorted. Thanks!
Usually binary trees do not allow data duplication. If you make a custom implementation you can store a count of elements. TreeSet in Java is an example - it contains only unique elements.
Actually the cases you listed broke the whole structure of the tree. Search operations will look weird now and couldn't be performed with O(ln n). It will take O(n) in worst case so you loose all the benefits of this data structure.
If this is a sort-tree, then what you have will work fine, either way; in the end you'll do a tree-walk and dump the data.
If this is a search-tree, then I'd just drop the extra (redundant) data once it's been encountered; "it exists". You did say this is a search-tree, and while not ideal, it's not actually broken - if you search for "4" you'll simply catch the root node (in this case), and never decend below that to see any other "4". It isn't optimal, having all the extra #'s around.
There will be best-case and worst-case situations regardless of which way you choose; don't worry too much about left/right decisions - generally just doesn't matter. IF you have a solid grasp of details in a known data-stream you'd be able to make an optimal decision for that specific case.
I'm working on a project that requires me to keep track of a number of points on a 2d plane. I need to add functionality that allows for certain points to detect the proximity of other points. I immediately thought of the closest pair problem and thought that maybe I should construct a minimum spanning tree.
The first issue is, these points constantly update their coordinates and I was wondering if it would even be plausible to do this.
The other issue is, I can't use 3rd party libraries for this so no jgraph or jung. I was wondering if there is a way to construct a minimum spanning using just the libraries I've been given. Can TreeMap be used or would I have to do this from scratch?
It sounds like you are trying to do Nearest Neighbor queries. That is where you try to find a point (or points) closest to another point. For a naive solution, you can just store a list of points and iterate through them using the distance formula to figure out which ones are closest. But if you want to do queries more quickly, you will want to use a spatial data structure that enables these kinds of queries. I would suggest a KD Tree. Java does not come with a KD Tree implementation in its standard library so you'll need to implement that yourself.
A TreeMap is just an implementation of the Map interface that lets you put and retrieve values by their keys. If you want to write something to generate a minimum spanning tree, you'll need to do that yourself.
On very Object Oriented way of doing this would have the Point Objects use the Observer Pattern and register themselves as Observers of all the other points, then as points positions change they can update all the Observers that they changed. You could control the thresholds of how often the changes occurred or by how much the changed needed to be by before the notifications were sent to the Observers. This would work well since you said, "certain" points need to track proximity and not all.
Hi
I want to make a binary tree which is based -level,which means that nodes of first level will be create and then all the nodes of second level will be creat and then all the nodes of third level will be create ,...
for making a binary tree like above ,I used a list(data structure)
I want to know that JVM can remember the order of nodes or I must use list?
thanks
You would need to use a data structure that maintains the links between your elements. If you just had an array and created everything at level 1, then created a second array at level 2, the JVM won't remember for you the order that things were created.
In short, you're likely going to want to use a Linked List for something like that.