How to reference a list on a Tab?

BomberFan

Member
Licensed User
Longtime User
I would like to be able to populate a list that exists on a Tab based on a selection from a prior screen: eg. Initial screen has say, a list of Vegetables (Potatos, Mushrooms, etc) and when you select one the second Activity is opened that contains a TabHost. On one of the tabs I would like to show a list of varieties of selected vegetable, another tab various wholesalers.

I have created the various pages and can load them onto the tab pages but cannot work out how to reference the list control on the tab page to be able to populate it from a SQL lookup.

This poses a number of questions:
1) Can you use Lists on a Tab?
2) If so, can you create them with the Designer and reference them from code or do they need to be created in code?
3) If yes to both of the above, what code allows me to make the desired reference?

Any assistance would be greatly appreciated.
 

eps

Expert
Licensed User
Longtime User
I've got something similar...

I created a ListView on a tab "page" and populate it. You can populate yours on the Click or LongClick event which initiates the display of the tab or page..

I think the solution is to create two lists at the same time.. So that they both have the same order, this is the key. Then display one of the lists to the user and then when they select this, use the position returned to get the id or key from the second, non-displayed list to then interrogate the database to populate the 2nd listview on the new/next tab/page... It seems to make sense in my mind (!) - I'm just trying to code something along these lines.. Using the Designer I created the members from it and am populating them with code right now.. I'll try and post code excerpts if I get to grips with it tonight.

HTH
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Just a few questions:
- What kind of Lists are you speaking of List, ListView or both?
- Do you really need a second Activity to display the Tabs ?

You could use several Panels in the same Avtivity to do that:
- a main panel to select the vegetable.
- a second panel with the TabHost
- 1 layout file for each panel
- 1 layout file for each tab
In the layout files for the tabs you add a ListView, and you access it with it's name.
Could you post the project you have already written, I could have a look at it.

You could also have a look at this example. It's not exactly what you need but could be interesting. It has an activity with a TabHost with 2 Tabs and a ScrollView on each. The ScrollViews are added by code but could also be added in the Designer. The ScrollViews could be replaced by ListViews.

Best regards.
 
Upvote 0

BomberFan

Member
Licensed User
Longtime User
Thanks for the suggestions Klaus.

I am really only just starting to look at B4a and am not yet familiar with how it all hangs together.

I will try some of your suggestions and see how it goes.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I'm doing something along the lines of..

...
ListView4.Initialize("ListView4")
Cursor = SQL1.ExecQuery("SELECT _id, name, startdate FROM event order by date(startdate)")
Log(Cursor.RowCount)
For i=0 To Cursor.RowCount-1
Cursor.Position=i
ListView1.AddTwoLines(Cursor.GetString("name"),Cursor.GetString("startdate"))
ListView4.AddSingleLine(Cursor.GetInt("_id"))
Next
Cursor.Close
...

So I populate ListView1 with displayed values and ListView4 is created at the same time, with the identifier, so for the same position in either list it holds the same record info. Then when something is selected in ListView1 I get the pos and set the pos in ListView4 to that value and retrieve the value stored in ListView4... It seemed like a logical way to do it, unless someone else can show me a mega easy/quick way to do all of this, which there probably is!

:)
 
Upvote 0

dealsmonkey

Active Member
Licensed User
Longtime User
You could just use listview1


B4X:
ListView1.Initialize("ListView1")
Cursor = SQL1.ExecQuery("SELECT _id, name, startdate FROM event order by date(startdate)")
Log(Cursor.RowCount)
For i=0 To Cursor.RowCount-1
Cursor.Position=i
ListView1.AddTwoLines2(Cursor.GetString("name"),Cur sor.GetString("startdate"),Cursor.GetInt("_id"))
Next
Cursor.Close

Now just catch the listview1_Click event and the value object will be Cursor.GetInt("_id")
 
Upvote 0

eps

Expert
Licensed User
Longtime User
yep, just seen the examples!! doh!!!!!

AddTwoLines2 (Text1 As String, Text2 As String, ReturnValue As Object)
Adds a two lines item.
The specified return value will be returned when calling GetItem or in the ItemClick event.

:)
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Much slicker!! :)

Many thanks for pointing this out, got it mostly working now :) Made things a lot easier!! Now I can keep primary keys in the list and remove items from a DB table using that value :)

excellent!!
 
Upvote 0

BomberFan

Member
Licensed User
Longtime User
Thanks everyone for your help.

I have just discovered that I can create (and see!) the secondary list if I create it in code. For some reason I have not been able to create the ListView on the secondary screen in the Designer and then reference that ListView in code to populate it and then make it all visible.

Happy enough to do this in code if it works.

All of your other suggestions will NOT go to waste. :)
 
Upvote 0
Top