I am a bit confused as I am new to android development. Let me put a scenario:
My app has 2 activities
SQL Lite DB related
List view
How should I use Android studio to combine both of the above? I cannot find a conclusive answer on the internet so that's why I am asking all the professionals out there.
Are you looking to have both in one page? In that case I would consider using Fragments, in which multiple to could housed into one activity and can run there. Could you elaborate more on what you are trying to do?
If you want to connect a ListView to some SQL database, there are many ways you can display that, but it depends on how the database is laid out.
Related
I'm building an android application that is very data intensive, and need to an interface to use to add data quickly and easily.
i've looked at all of the database tools, none of which make it easy to enter data using foreign keys. I need all the foreign key fields to show up with dropdown lists (for 1-1) or checkbox lists (for *-1) for fields to make it easy to enter data.
The closest I've found to achieving this is the following:
http://www.sqlmaestro.com/products/sqlite/datawizard/download/
Which claims to generate ASP.Net forms from a database. Does anybody know any other tools that'd help me?
I guess I could build my own forms,but would prefer to spend my time developing my app. I'd be happy with a framework to kickstart development of my required forms, maybe somebody has done something similar already? (ASP.Net preferable but not a necessity).
I know the aspnet maker.
http://www.hkvstore.com/aspnetmaker/
Can create very fast a full site that handle your database manipulations.
Its not free, and you stick with what ever he gives you, but is not that bad for quick tool.
From the other, do you ever hear the scaffold ?
I have use the SubSonic ver 2, that have scaffold, but other DAL have also.
What this technique do is to automatic create the editing forms for your.
you can search on google for "scaffold asp.net"
So you can select a DAL that have scaffold and use that.
So I have an Android app that is running in a TabActivity that separates 3 different activities through this tabs. I've set a DatabaseHandler class with SQLite and all, fine.
The thing is, so far I don't really know how to deal with the database since it will be receiving data from one of the activities and I need to be showing that data in a different one. I don't know if I should declare the db in the main TabActivity or where, I've never worked with SQL in Android before and I'm pretty lost at the moment.
I tried to picture it so it is more understandable: Explanatory Graph (Sorry, I don't have enough reputation yet to post the image into the post directly)
Thanks in advance.
Although using your DatabaseHandler is posssible within each activity in the long term I think most non-trivial apps would benefit from using a ContentProvider
ContentProvider provides an abstraction over your data. It becomes really powerful when you combine it with a CursorLoader and LoaderManager available back to Android 1.6 by using the support library.
These concepts require a bit of study but will make sharing data across multiple Fragment or Activities simpler and less error prone.
Mobile Tuts has a couple of good tutorials that are worth reading on top of the official Android documentation and examples:
http://mobile.tutsplus.com/tutorials/android/android-sdk_content-providers/
http://mobile.tutsplus.com/tutorials/android/android-sdk_loading-data_cursorloader/
You should be okay, as long as you close your connection with the database as soon as you're done reading/writing to the database.
Each activity should be able to have their own DatabaseHandler.
My project is a visitor app for a University, that basically displays places and events on a map, and allows the users to interact with one another by making posts with advice/recommendations/questions and so on.
So far I've been trying out bits of code seperately (lists, tabs, the basics), following the android tutorials and trying things for myself. My problem is that I'm not sure how to combine all the bits of code into one project.
I know that I need to make a database, and a map (using OSM rather than google).
The database will store information on places, events, and posts that users have made. With co-ordinate information because they need to go on the map. This information is also displayed in seperate tabs - e.g. a list of places.
My problem is that I don't know how this will all fit together.
Will I need seperate classes for the database, populating the lists, and displaying on the map? Or can they all be in a single class?
I'm a little hazy on how the classes and activities are going to communicate, too. At the moment I'm thinking the database object is going to get passed to the listviews and mapview, which then take and display some of the information?
Any advice on how to cobble these elements together would be much appreciated. :D
I think I will need to subclass SQLiteOpenHelper for my database, so it'll need to be its own class?
I'm thinking of using OSMdroid for the map, which I'm not sure how to do yet.
And everything needs to be inside a tabview.
Welcome to StackOverflow!
Your question is very vague and broad, and likely to get closed as "not a real question" - I suggest you take problems one by one and ask specific questions as you go along and run into problems. Try to think about your problem in these terms: what's the minimal thing I need to get it to do the thing I want. Keep in mind that ANYTHING you want to do is possible, the main question to ask yourself is: what do you want your application to do exactly? Think about the number of different screens (activities), and how they would communicate to each other (when you click XXX, that will lead you to YYY, and so on). One advice: start simple, it's very easy to get buried in too much complexity, especially since it's your first project. It can quickly become very complex, even with a simple concept.
As you didn't specify your level of expertise in coding, it's difficult to give precise advices: but coding an android application is not very different from a "regular" application, with a web or Swing or C# user interface. So I would advise you to learn about OO programming in general, things like composition, inheritance, encapsulation, dependency injection, unit-testing, etc.
Then start writing a base Activity for your main view, write its layout, and add views and graphical elements to it. Then add the listener code for your widgets, that will generate Intents to other Activity.
Then add a DatabaseHelper when you want to save stuff in a database (that can come later, to begin with, you can just "stub" the interactions to a database, by writing what you would save to db on screen using Toast for example).
All objects can be injected into other objects by passing a reference to them, either at construction time or through setters.
Sorry not to be more precise, as I said it's a very vague question.
I wish to use database for my application.How to use the database in android.I use eclipse ide.Is there any requirements need for create database.Give some basic ideas about it.I am android beginner.Help me to know about it.
Since this question is worded almost exactly like how to use database in android? I would say you created a duplicate question. if not, see that question. If you need more, supply the info you would like to the initial answerers.
I think you should see Notepad sample project. There are a lot of common android practices there including database stuff.
im working on a simple Android app, it is much like any other simple Database app. I have 4 EditText fields where the user inputs 4 different small pieces of text. I want this text to be inserted in to my Database table in the corrects rows for my columns. I am not really sure how to go about doing this. I know onClickListener needs to be used but not sure how to use it.
What you are looking for is the glue to make it work, as you have a storage ( your database ) and the user interface. But, as you pointed out just right, your onClick actions, or more widely spoken, your whole user-interaction needs to be filled with action.
I won't give you a specific advice here as I think you should read a bit about the Model-View-Controller Pattern here, as well as about how Android handles all that stuff. A good entrypoint for gaining knowledge is, as always, Wikipedia.
Don't get me wrong, I don't mean to offend you by not answering the specific question: I just think it's more valuable for you to first learn the basics required for building great apps instead of reading a step-by-step manual!
On my phone right now, but you are correct about setting up an onClick method for, let's just say, a Submit button.
I would look at the Developers Guide on the SQLiteDatabase on ways to insert values by executing a SQL statement or check into using ContentValues to insert values when the button's pressed, both could help you out.
Also, with a fair share of knowledge on databases the Developer Guide should be all you need, but if you need further help search for related questions.
NOTE
A good practice is getting used to debugging your code using LogCat. It helps when things go astray, especially when working with databases.
Tne Notepad Tutorial in the Android Developer Documentation takes you through creating an application which stores data from fields in an SQLite database.
You could work through this, or if you didn't want to do that it would be a good source of sample code.