Android: Is there a Tree Package (Datastructure) I can use? - android

I'm trying to convert a Java Program to Android. I created a new xml Interface and most of the core logic is still running but since Swing is not present in Android i'm missing the class javax.swing.tree.DefaultMutableTreeNode in particular.
Is there an easy way to replace the class with something equivalent in Android?
Thanks in advance!
Taber

There is no Tree view on Android, so there is no directly comparable class.
But, if you need to use a tree-like data structure to display it's data in UI, for example in ExpandableListView, then you can use CursorTreeAdapter.

Related

Does Android SDK suggested with MVP design pattern?

I've read about MVP design pattern and have some question about it.
If we consider Android SDK we can suggest that an Activity is a Presenter which takes over event handling, lifecycle events executing and communication with data-layer which can be a SharedPreferences, SQLlite etc. View in that case is just xml- view description which doesn't contain any event handlers or other user-communication things.
But I'm doubt if my reasoning correct at all? Could you help me to understand?
Android also follow MVC architecture.
1) In Android activity is the controller where you write a code for handling input & response.
2) xml layouts represent the view where you describe the presentation part of the application.
3) & model is your java pojo classes. For instance Person class which has two attributes first name & last name.

Activity is getting too large and becoming more and more difficult to work with. Solutions to solve this issue?

I am working on my second Android Application, first being, hello world. The application code is quite crazy looking because I love to test new libraries and ideas in it. I have been working on this application for well over 3 months and one of my activities is getting way to large and difficult to work with. I find myself getting lost in the code and it is taking longer to do simple things. There might be simple solutions to solving this issue. I really want to split my activity into two and reference each other if possible. Is there are any suggestions to simplifying and organizing code that would be greatly helpful. Even example will help me very much.
Part of my activity is adding a ton of data into a database and the other part is a long equation with multiple values. Another part is implementing the HoloGraphLibrary (Which I love). It is also implementing a listView with custom adapter. It also has a custom dialog............ I can go on and on. I hope you get my point.
EDIT
Going to work with this.
HoloGraphHelper holoGraph = new HoloGraphHelper();
holoGraph.initialize();
Try creating classes for each responsibility.
A Database Helper that has functions to insert data too:
DatabaseHelper database = new DatabaseHelper();
database .insertData(whatever);
A HoloGraphHelper that initializes the HoloGraph
HoloGraphHelper holoGraph = new HoloGraphHelper();
holoGraph.initialize();
And so on.
Break into multiple files. First classes defined in the Activity like the adapter. Change anonymous classes to classes defined in their own file. Look for ways to break out other related code into a class.
Right click on src folder of your Project and select new - class to create a new class. You can use a class for storing methods but you won't be able to display anything on screen.
To display contents to user, you can create a new Activity bu pressing Ctrl + N and selecting Android - Android Activity.
The best way is modularise your code.
I.e split your code into various related modules, for example a separate class for each part that your testing. So you could have a database entry class, a class for Gui testing, i.e. for your custom dialog. That class does all the work for that test, into various functions, I always try to keep functions as small as possible as they are easy to read.
As an example for your database entry, you could have a function which checks the database if the record already exists and then insert it. But a better way would be your insert function only performs the insert code and instead within this function it calls CheckIfDatAlreadyExists function which can return a bool so you know whether you should go ahead and insert the record. This would keep the code tidy and clean to manage.
Then from your main activity all would need to do is instantiate the relative class and call the relevant method.

xml beans in android

I want to use xml beans in Android. I searched around one day in google and i some places read , i can't use xml beans in Android and Android not have this and now i am confused! I dont know, i can use this or not and if i can't use this, What should i use instead of xml beans? I don't want use maven.
xml beans configuration is just in spring?
I can use xml beans in Android? if yes xml beans from spring?
I read, use xml beans could slow my App. this is true? if yes what should i use instead of this for increase performance app?
I goal from use xml beans this is:
I want to create a bean xml file that i set all of my classes(with my packages) and i want in id tag in bean tag, set a method name from my class. like below: () and with this, i can get SMS method from sendingSMS class with reflection. I mean i can send method name and parameter from this method to reflection class and then call method. This is a training sample for learning android and java bean and reflection in android and then use this in real project.
and I see use xml beans in java like this link (use beans in java) but i want use this in android
Thanks for your help :)
Maybe you can user XStream Library in Android
Xml Parse would slow your app? No,I think it decides your parse method.

Trying to pull API into LinearLayout Android APP

I am a beginner of Android apps and am using Eclipse. I have found some larger samples of pulling APIs but I cannot find a simple one to get started with. I simply want to pull from an XML file on the web (by using an API KEY) and throw it in a LinearLayout (Vertical). I can then go from there, anyone know of any? Below is a sample of my XML:
<xmldata>
<Products>
<ProductCode>ITI-GR12</ProductCode>
<ProductName>Granada 9-3/4" Narrow Rim Platter</ProductName>
<ProductPrice>64.4000</ProductPrice>
</Products>
</xmldata>
I am assuming you are looking for mechanisms which help you to parse XML and extract data from it...Voila here is a link to get you started with different ways of doing it...
http://www.ibm.com/developerworks/opensource/library/x-android/
Good luck!
your question is not easy as you will have quite a lot of programming to achieve what you want.
Here are the steps :
read your data using sax
fill a data structure of your own (build a
class, data members will be filled by
previous parsing)
build an activity, use a layout you define to
show all UI fields you think you need
to display your data
fill the content of each view using the data
structure you filled on step 2.
If you are a beginner, I suggest you first understand steps 3 and 4, having fun with UIs, then try to understand how you could download your file, parse it and fill some data class to provide content for the views.
Regards,
Stéphane

Android - Getting data from XML file on the web

I need to get data from an XML file in Android. On the iPhone environment, my code is:
NSURL *thisURL = [[NSURL alloc] initWithString:#"http://www.xxx.com/file.xml"];
NSArray *myArray = [[NSArray alloc] initWithContentsOfURL:providerURL];
myArray is now an array of dictionary items initialized with contents from file.xml.
Is there any way to do this in Android? Can someone point me to doc or sample code?
I'm new to the Android environment and just need some direction.
Thanks,
Kevin
See Working with XML in Android for a variety of methods for dealing with XML. Which method to use depends on how big your XML is, and what you want to do with it. '
I'm not sure how it makes any sense to turn XML into an array, so no, none of the methods do that. If you want something similar to that, use Json instead of XML.
After a bit of research, it appears to me that using the Simple XML Serialization framework is going to be my best bet, especially since I do have a relatively simple XML file to read. The result will be a 'list' class with several 'entry' classes which seems like a viable way to handle this...probably better than having an array of classes as was done in the iPhone app.

Categories

Resources