Android Question How to make a copy an object

msali

Member
Licensed User
Longtime User
Even though I have been using B4A for almost 10+ days, this is my first post at this forum as all of my questions that i had, have already been asked and responded to.

I am at the last stages of my first big application and all of a sudden i have hit a dead end and do not know how to go about it.

I have used multiple code samples from this amazing site and supporting people and staff. So thanks to all of you.

My problem is that i am creating a list of players to create a score card. User will be able to add players that they have defined. Every time a player is added in the list few labels are added in the list (Custom List View - CLV [CustomListView 1.16] - also downloaded from this site and made some modifications to it as per my need).
No issue so far.

One of the controls in the CLV is the table (Table [TableV1_36] - yet another reuse of code from this site)
The table has 20 columns and takes at least 8 seconds to be loaded. My plan was that once I have created a table I will save it in a List object and when new player is added I will extract it from the list and assign to a newly created and initialized variable so user does not have to wait for 8-10 seconds every time they add a new player.

sample code is as below:

B4X:
pnl.Initialize("")
pnl.RemoveView
pnlPlayers.AddView(pnl, pnlScoreCard.Left, 0, pnlScoreCard.Width, lbl_Strokes.Height)
pnl.Visible=True' tbl.Initialize(pnl,"", iMaxHolesPerRound+2, Gravity.CENTER_HORIZONTAL, False)
tbl.AddToView(pnl,0,0,pnl.Width,pnl.Height)
tbl= lstCtrlTable.Get(0)


(I know it is logical that this new tbl variable that i get from lstCtrlTable is the same as original)
Now when i make changes to the content of the table the original table gets updated.

I have also tried RandomAccessFile write object and then read it but it did not work properly either as suggested in http://www.b4x.com/android/forum/threads/copying-an-object-not-just-a-reference.12816/

It gives a Java Null Pointer error after i Read it back and initialize it:

B4X:
tbl.Initialize(pnl, "", iMaxHolesPerRound+2, Gravity.CENTER_HORIZONTAL, False)
tbl.AddToView(pnl,0,0,pnl.Width,pnl.Height)



Summary:
I need to know if i can make a copy of this variable and use it again and again with every new player added in my app. All the logic of my app for calculating running scores is built around this table.

Thanks in adv
 

msali

Member
Licensed User
Longtime User
Erel: Yes i am using it in Release mode; and every time i add a new player to my CLV it takes same amount of time.

Klaus: Yes i want to add a table object in each row of CLV.

Just to give gents an idea of my app, it is a golf score card where i need to keep track of score of 18 holes each for every player (upto 4 player per round). Also need to keep track of 18 holes of putts which make it 36 columns but since the class that i am using is so slow, that i am restricting it to 18 columns so far.

So:
Player one: table 1 with 18 columns in CLV index(0)
Player one: table 2 with 18 columns in CLV index(1)
Player one: table 3 with 18 columns in CLV index(2)
Player one: table 4 with 18 columns in CLV index(3)

I know there must be other ways of doing the same but I am tooooo far in my design to go back and change. Therefore, my idea was that once i create table 1 i will make copy of it and every time a new player is added i will just use the copy and not go through creating a new instance of table and take another 8 second.

Attached images are screen shots of same screen with Horizontal SV in the upper part of the screen.

Thanks for your support.
 

Attachments

  • KGs-1.png
    KGs-1.png
    102.6 KB · Views: 188
  • KGs-2.png
    KGs-2.png
    90.7 KB · Views: 191
  • KGs-3.png
    KGs-3.png
    91.6 KB · Views: 187
Upvote 0

klaus

Expert
Licensed User
Longtime User
I'm sure that your aproch is the wrong way.
Adding a Table class in each CustomListView item will become a montrous container.
How many Tables do you expect to add ?
Be aware that the Table class is a relative big object.
I'm afraid that you will have scrolling trouble because CustomListView has a vertical scrolling and the Table has a scrolling in both directions.
 
Upvote 0

msali

Member
Licensed User
Longtime User
Well, i also figured that out - the hard way :)

I have now created my own mini table library to get through with this project and thus far it is working fine and like a charm. It is a single row table.

So technically I am over this particular problem and may consider it is closed but just as for my knowledge why was the RandomAccessFile method not working with the table class.

Thanks for your response & support.

ps: You guys rock (you must have heard this a million times) and B4A tool rocks too
 
Upvote 0
Top