How would I get a ListView from ListActivty INSIDE a class that extends on TabActivity?
-
29-09-2019 - |
Question
Newbie here, bear with me..
I have a class that extends TabActivity. One of my tabs currently contains one long string composed of some records i got from my sqlite table. Now i'm following a tutorial and the next step is to move away from the string and create something a bit more appropriate for the records, a listView. However it says i'll need to change my class to extend ListActivity but i've already extended TabActivity (not part of the tutorial)and i don't really have the knowledge yet to know where to go from here.
I figure if my tabs content was set with intents to separate classes I wouldn't have a problem but it's important to me that both the tabs and their content are constructed in the same class because i will want to be doing a lot between them later. But maybe there is no way i can avoid creating a separate class? If so could i still point both of my tabs towards the same class? for the same reason as above. But then how would i get them still displaying different content?
I sure there's an obvious solution but i don't have enough programming experience to have a clue what it is, I've been googling a while now but i'm not really sure what to look for so if somebody could point me in the right direction i'd really appreciate it.
Hope I'm talking sense, Here's a link to see the class i'm working on:
Solution
You don't need to have your class extend ListActivity
(or TabActivity
for that matter) as those classes are just a convenience.
If you want to show a ListView
in a TabActivity
, check out this tutorial I wrote.
OTHER TIPS
You can always insert a ListView to your activity, give appropriate android:id
so you may refer it to handle data. Theres no compulsion that a ListView must be in a ListActivity.
See my comments so I can help you more.
You don't mess with the TabActivity
as this Activity
just manages all of your tabs. You just set the new ListActivity
as the content of the tab you want to display it in.
Check out the Android Hello Tab View tutorial as it shows you how to assign an Activity
to a tab which is just what you need.