Android: Listview in a tab activity - android

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 .

Related

ListView pass data to another ListView

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.

How to update the UI in android

I have an activity A with a listview and upon selecting some items in the list, and navigating to another activity B with the selected items in the list of Activity A. And made some modifications. After return to A. My screen is not updating with the latest modifications.
Please guide me how to do this. Thank you in advance.
If you have unified data storage for both activities (so that you know that this problem is purely UI issue, because the data itself is updated upon returning from activity B), then you should call this method on your ListView adapter:
yourListView.getAdapter().notifyDataSetChanged()
In order to display what you want, you need to have some TextViews in your other activity and then just add a text to them to display what you need.
When you get the data, just do like this in the onCreate method:
TextView tv = (TextView)inflate.findViewById(R.id.myTextView);
tv.setText(theDataStringYouReceived);

Display db content in another acitivity by clicking on item in listview

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

ListView dynamic onClickListener USING Database ID

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.

How to get a selected contacts?

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

Categories

Resources