I'm new to Android. I have two activities. First activity shows selected contact list from second activity. Second activity shows contact list from database with checkbox. Now I can read a contact list from database and shows at checkbox. Therefore I don't know how to pass selected contacts from first to second activity and how to display selected contact list. Is there any easy way to do it?
Thank you for every advice and guide.
Thanks,
Zeck.
First you have to get Data from your database
then create a CursorAdapter or any Adapter you want and
fill it with data and override getView() there.
Here http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html
and here http://thinkandroid.wordpress.com/2010/01/09/simplecursoradapters-and-listviews/
Set your adapter into a ListView then
implement onclicklistener on this ListView
where you will pass the data to Bundle and start a new Activity
listView onclick goes to a new activity
Here
http://thedevelopersinfo.wordpress.com/2009/10/15/passing-data-between-activities-in-android/
and here
http://geekswithblogs.net/bosuch/archive/2011/01/17/android---passing-data-between-activities.aspx
There're many other ways how to share the data between activities
like SharedPreferences or Sqlite database. But it's not the topic for this answer.
hope it helps abit
Related
I have two activities with List View's:
Activity A --> ListView person
Activity B --> ListView favouritePerson
In person ListView there is a button i every item of the list
person --> Button likeButton
I would like to add person to favouritePerson list when the like button is clicked. I was trying to achieve this by adding data to singleton and then trying to get it from there, but without success. I have also tried to use SharedPreferences, but could not get it right either. What would be the best approach for this workflow?
I also forget to mention, that I'm populating the first listView by querying the Realm database.
I would like to add person to favouritePerson list when the like button is clicked
To get this, onClick like button, you need to write a query to insert favourite bit in data base against that record. And when you load activity B updated data will be populated. No singleton, sharedpreference or Parcelable is required. This is the best approach. Update database record on the fly and get updated data in Activity B.
So I have this problem, my listview is populated from Sqlite DB and I can click on any item in the listview. When I click on an item I want to display, in a new activity these "name, surname, age etc" details but these should be retrieved from my database.
Can anyone help me?
Thank you.
Use onItemClickListener method in your listview. When user clicks an item pass the item into next activity and in next activity retrieve data based on the item click. This tutorial will help you to get a good idea.
Import and Use External Database in Android.
Set an onItemClickListener for your ListView and when an item is clicked, you could either:
Place into a Bundle the details you want to be given to the Activity intent
Or
Place as an extra/bundle to the Activity intent the ID of the item you retrieved, then retrieve the details you want from the DB using the given ID inside of the next Activity
I have an activity which contains listview, when click on any list item, i want to display same activity with listview with different data and so on.
When i click on back button i need to display same activity listview with old data.
Is it possible? or is there is any other way to achieve this. I dont want to create any new activities or fragments for this?
Thanks
KrishIndia
You can write the function such that each time you click an item, it generates the list, assigns the data to your adapter and attaches it to your list view of choice.
If fetching the data won't be expensive for you, you could use only one adapter (array adapter or list adapter or simple adapter should be fine) and just re-assign it each time. (Ex. If you were listing files in a directory, inside your onClick() function you would have some function declaration like list_items(directoryName) that you would call each time. That function would declare and set an adapter for your data.)
If you are concerned about the expense of re-fetching the data, just store multiple adapters (outside your onClick() function) and set them to your list view as needed.
on click of list item just set new adapter or new data and call notifyDataSetChanged()
and for backpress override onBackPressed() and handle accordingly
Maintain separate adapter for each new data. When you want to return back just pass the relevent adapter object to that list view
I'm creating a restaurant menu app with categories and items loaded from database and put them in a listview. Every category has it's own items. I would like to following behaviour: when I click on some category it should go to another activity and list it's items of the category id that listed in DB.
How do I create a dynamic onItemClickListener to send that ID to another activity to load it's items?
Its not about dynamic listener. Listener should be only one which would send chosen category id to somewhere where you could use further. Like sending it in intent's bundle to some activity.
I have this app that there's a list view within the tab activity. This app is a messaging app. It doesn't really send the message, it just saves it to the database and the database will display the message in list view where you can edit it/delete and/or resend it.
So when the user taps on the send button the message is saved to the SQLite Database and the data on the database will display on list view. I have two tabs, one as the history/sent messages or the list view and the other one is new message or editing page. How do I insert the list view that has the database in tab activity?
I only have a simple code for a list view and I copied the database in the http://developer.android.com/resources/tutorials/notepad/notepad-ex3.html. Well basically i just edited their work because the tutorial has everything I need, editing, deleting and storing, the problem is how the list view of database in a tab activity.
What is the issue . create Activity with a ListView ,set Adapter (CursorAdapter is preferable) add to TabSpec , now addTab .
ApiDemoes will be enough to get more idea .