How to add a custom field to the contacts in android? - android

I want to add a custom field to any new contacts created in the Android programmatically. Say for example birthday?
Please help me in this regard.

Do you want your custom field to be clickable and to be able to view it from an activity?
If so, you would need to created a synchronization service between an Authenticator and a SyncAdapter.
Check this project, where the code adds new account with custom field, which can be viewed in some activity: https://github.com/nemezis/SampleContacts.

Related

Handling a large number of items in a listview

I am creating a directory of schools in android application and want to open their details on new page by clicking on it from list view. how should i handle it?
I would recommend to use a RecyclerView.
You can find a simple example here.
make Pojo of the student info and pass it to the next activity using parcelable object

Session state of ListView

I am new to Android App development, working on an android app which populate a list of numbers, in a listview dynamically, depending on the choice of the user, but, the moment user closes the App, the items in the listview are lost. How can I maintain the state of the listview?
Examples with code would be highly appreciated.
When I open Activity A, it allows users to add friends, and this friend list is shown in the form of items of listview in the same Activity, however, when I move to Activity B, and then come back to Activity A, this friend list disappears. I need to make sure that this friend list should not be lost while moving between activities. Please help.
I think that for your purpose there are 3 main methods, i'll explain them from the easier to the most difficult (in my opinion).
Text File
A way to do this is to create two methods in a class:
one has to create the text file in the storage if it isn't created before and read that, the other has to append a String to a StringBuilder and write it on the previous text file.
For this method you need the uses-permission of reading and writing to storage.
This link can help you: http://developer.android.com/training/basics/data-storage/files.html
JSON (also XML)
With JSON file you can create a list of objects with your data that you can serialize when you update the list and deserialize when you want to read it. For this purpose you have to study JavaScript syntax or, at least, JSON one.
SQLite Database
Android SDK incorporate a class named SQLiteOpenHelper that you can extend to create a database inside your app.
This link can help you: http://developer.android.com/training/basics/data-storage/databases.html
There are also references saving methods but i think that aren't right for your purpose, they work betters to save something like preferences or single data like last login informations.
I went through your comment. I would personally suggest using SQLiteOpenHelper
You might need to understand the use of SQLite, hence the tutorial
Simple Flow. On your Activity 1 where person Add Friends save it to DB
Then refresh the List from the DB. So when you move to Activity 2 and come back again to Activity 1 your List will refresh from DB. Hence no loss of data as you want.
EDIT
As user wanted to know how to use the ListView with DB.
Following are my suggestion
Sai Geetha
Youtube

Search implementation Questions on android

I am a newbie here and hope you can help me out to clear some of my understanding (or misunderstanding). I have been reading for days and trying out based on Android guide to implement search function but it really didn't work out well. Perhaps I've got the whole concept wrong so do help me out here if you can be kind.
I have an app which data is from remote xml and I want to implement search function. I have 1 main activity (under my SRC -> my package)that list all the data retrieved from the xml. My questions:
1) In the guide, it saws we must define a .Searchable Activity. I supposed this is to handle the search query and store the result? If this is a case, do I need to create a new activity or I can use my main activity as .Searchable Activity?
2) After the above item is done, I supposed I need to create an activity to receive the result and do something. I take it as I need to create "public class SearchableActivity extends ListActivity" in the activity I define in item 1? The problem is that I don't know what to do with this as the guide are incomplete.
3) Presumingly I did it successfully and upon search, there are some results return, how do I show (or filter to show the search result) in my main activity? I do not want to have another UI to show the result as I prefer it just get filter to show the matched records
4) Lastly, since my data is from remote xml, do I need to "search" based on remote xml or it will search based on cache info on the app?
I am sorry for being so ignorant but I am totally new here and hope you can help me out. So far I have no problem, getting the dialog shown on my action bar. The only problem is that the search didn't work at all :( upon search, there is just nothing happened.
Thanks very much in advance. Cheers!
For searching in a list you can use built-in functions of android, but if you want a good result you can use your own function. The simplest function is:
for(int i = 0 ; i < arraylisy.size() ; i++)
{
if(arraylist.get(i) == youobject)
return true;
}
return false;
but there are better functions like binary search that you can use.
Now, how to create search activity?
First: create XML file an add a listview in it.
Second: create java file and link xml file to it.
Now use above code to search an object on your list. If in every search you find several items then add them to new listview.
Now create an adapter and send your search list to that.
Finally set your adapter to listview.

Dynamic flow in Android application

I am developing an eCommerce where I am fetching the Products and sub-products from database at run time.
Here the depth of the sub-products is not fix, means that I don't know at build time that a sub-product of clothes e.g. jeans, again have a sub-product or not.
I think to create Activities dynamically but as per Android Documentation we can not done it.
We have to specify Activities in Android Manifest.xml at build time.
As per your Question you want to display Products and sub-producs dynamically in your application. for that you should have to use Listview to display your UI part and use AsyncTask to Load data from your database/server.
ListView Tutorial :: http://www.vogella.com/tutorials/AndroidListView/article.html
AsyncTask Tutorial :: http://developer.android.com/reference/android/os/AsyncTask.html
First of all you need to clarify the data structure of the product defined in your application. There should be relationship such as foreign key or other constraints defined on your eCommence backend database.
So, there is no need to create activities at runtime. Instead, try to define a base activity to handle the common product operation and other special activities that extend the base activity to handle the differents between the product and the sub-products.
The logic may like this:
Load product data in common activity. then the app decide whether to load the sub-porduct via creating special activities according to the data flag/key defined in product data retrived from database, and so on.
I think expandable list view is best option for that.Because it clearly shows your main product and sub-products to the user.To create and understand expandable list view please see below link :
http://theopentutorials.com/tutorials/android/listview/android-expandable-list-view-example/

Spinners - custom input

I am new to making android apps and was trying to find out if there is a way for a user to add their own custom selections to a Spinner.
For example I want to make a database for keeping track of car maintenance.
So I want the user to be able to add/remove their own cars/trucks as needed to it.
If there is a better way to do this I am open to any suggestions.
I am using eclipse.
Thanks for any help in this matter.
So two ways to do this,
First off since you are using a database I would look at using a SimpleCursorAdapter or a Loader to manage the connection and updates to the db, so you don't manually have to refresh the query, and use a SimpleCursorAdapter to power the spinner like this answer https://stackoverflow.com/a/11216746/418505
Or, you could programmatically query the database and then use some UI event hook, like a button click to submit the new car/truck to then update whatever Adapter you have bound to the spinner (make sure you call notifyDataSetChanged)

Categories

Resources