I am a new developer in Android. Currently I have started working on an app. I dont hav开发者_如何学编程e any colleagues in Android so for my doubts and queries I am depended only on Stack overflow.
In my app I have placed three Edit boxes as follows with an ok button at last
FirstName:_____________ LastName:______________ DOB:___________________
When the user enters all data above and clicks the OK button at last, I am going to do the following process
- Store the datas in a database
- Send it to a particular URL
- the data send to the URL will be get saved there
i just want to know how to implement this. What concept to be used.....
The actions, views and activies in Android are the baked in way of working with the Android UI and are an implementation of a model-view-viewmodel pattern, which is structurally similar (in the same family as) model view controller.
To the best of my knoweledge, there is no way to break out of this model. It can probably be done, but you would likely lose all the benefit that the existing model has, and have to rewrite your own UI layer to make it work.
You can find MVC in the followings:
- You define your user interface in various XML files by resolution/hardware etc.
- You define your resources in various XML files by locale etc.
- You store data in SQLite or your custom data in /assets/ folder, read more about resources and assets
- You extend clases like ListActivity, TabActivity and make use of the XML file by inflaters
- You can create as many classes as you wish for your model, and have your own packages, that will act as a structure
- A lot of Utils have been already written for you. DatabaseUtils, Html,
There is no single MVC Pattern you could obey to. MVC just states more or less that you don't should mingle data and view, so that e.g. views are responsible for holding data or classes which are processing data are directly affecting the view.
But nevertheless, the way Android deals with classes and resources, you're sometimes even forced to follow the MVC pattern. More complicated in my oppinion are the activites which are responsible sometimes for the view but nevertheless act as an controller in the same time.
If you define your views and layouts in the xml files, load your resources from the res folder, and if you avoid more or less to mingle this things in your code, then your anyway following a MVC pattern.
Google has tutorials for doing simple forms and taking actions when buttons are pressed. You should start there.
Next try the URL thing and next try the save data thing. If you follow the form tutorial you'll know where put code to execute when button is pressed (read the data tutorial).
If you follow others tutorials (to navigate) you'll know how to redirect to a URL (I would read "intents" but I'm not pretty sure, I'm not very prepared on Android). I guess that you should only "redirect to http://" and the system will decide (or ask the user) to open it in a browser or something diferent (like the youtube app). If you want to control the window navigation read this (but I don't recommend it).
But the bottom line is: read the tutorials and try things until you feel that you grasp the philosophy of the technology. Then search for specific things link redirecting, saving data, or taking a special action.
精彩评论