Android Question Get All Items Values into Arrays

Adamdam

Active Member
Licensed User
Longtime User
Dear All,

From this tutorial: [B4X] [XUI] CustomListView - lazy loading / virtualization

I create CustomListView which has EditText, CheckBox, ..
I need to copy all items data into array of strings, like the following code:
this code is not right, I need to correct it:

Dim StrArray(100) as string
Dim ValArray(100) as int
.
.
For i = 0 to maxItems
StrArray( i ) = CustomListView...EditText1 ( i ) ' this code not right , I need to correct it.
ValArray( i ) = CustomListView...CheckBox1 ( i ) ' this code not right , I need to correct it.
Next



wait for correct previous codes to copy all items data into Arrays as above.
Thanks in advance.

Best regards
 

ronell

Well-Known Member
Licensed User
Longtime User
dont know if this works.. but this might give you a hint

B4X:
Dim StrArray(100) as string
Dim ChkValue(100) as Boolean

For i = 0 to CustomListView.GetSize - 1

dim pnl as panel = CustomListView.GetPanel(i)

dim lbl as label = pnl.GetView(0)
dim chk As CheckBox = pnl.GetView(1)

StrArray( i ) = lbl.text
ChkValue(i) = chk.Checked


Next
 
Upvote 0

Adamdam

Active Member
Licensed User
Longtime User
thanks Mr. ronell for your answer,
I test your code, but it give me error, " not initialized " . how can repair this error ??

another question, i have many/different objects in each CustomListView, how can i know the orders of these objects in panel ?

best regards
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
I test your code, but it give me error, " not initialized " . how can repair this error ??
make sure the customlistview is initialized/loaded in the activity before using the loop.

i have many/different objects in each CustomListView, how can i know the orders of these objects in panel
i rewrite the code so that you dont need to know the order of the views

B4X:
Dim StrArray() as string
Dim ChkValue() as Boolean

For i = 0 to CustomListView.GetSize - 1

dim pnl as panel = CustomListView.GetPanel(i)

 
    For Each v As View In pnl.GetAllViewsRecursive
        If v Is Label Then
         
            dim lbl as label = v

            StrArray(i) = lbl.text

        Else if v is CheckBox then

            dim chk as CheckBox = v

            ChkValue(i) = chk.Checked

        End If
    Next

Next
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
another question, i have many/different objects in each CustomListView, how can i know the orders of these objects in panel ?

Refer to the order in Designer ViewTree for Item/Row layout ... this dictates the index of the CLV panels views.

note you can also directly reference a views properties without declaring another view. ie:

B4X:
For i = 0 to CustomListView.GetSize - 1
    dim pnl as panel = CustomListView.GetPanel(i)
    StrArray( i ) = pnl.GetView(0).Text     ' 1st view listed in Designer ViewTree for CLV Item/Row layout
    '............
 
Upvote 0

Adamdam

Active Member
Licensed User
Longtime User
Dear Mr. Ronell, and Dear Mr. Mangojack
Many thanks for your interesting and for your answering.

Mr. Ronell, your code work well,
sure I initialize the customListView first and it even filled by user,
I try to make little change as: (not work)
Dim vv As View = pnl.GetView(2)
Dim lbl1 As Label = vv
Log(lbl1.Text)
while your code work well, Are you have solution to run my little change ?


Mr. Mangojack, for the ordering, you are right,
but the code you attached not work, where parameter "Text" not defined with "pnl.GetView(0).Text"

best regards
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Adamdam

Active Member
Licensed User
Longtime User
Dear Mr. DonManfred, Dear Mr. Ronell

Many thanks for your interest and answering.
attached example.
still have one problem : all objects work well except CheckBox ( not work )
(in attached example : press done button to see all information of cards in log)

Hope to find solving for the problem of CheckBox.

Best regards
 

Attachments

  • CardsList_2.zip
    110.6 KB · Views: 91
Upvote 0

Adamdam

Active Member
Licensed User
Longtime User
Dear Mr. DonManfred, Dear Mr. Ronell

Are you test the previous attached example ?

Hope to find solving for the problem of CheckBox, it nod defined so, it not read.

Best regards
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
The reason you were having problems / errors .. The Card List has all views placed on a secondary panel which had to be accessed first.

There is no need to loop thru all views testing for there type prior to accessing them. Deal with them directly.

I am still unsure what you are trying to do in regards to 2nd array and checkbox value / state ? (post #1)

Try the attached project ... Click and Study code in the DoneBn_Click sub.



PS: Apologies on behalf of Mr. DonManfred & Mr. Ronell not replying ... I believe they were at the Races .o_O
 

Attachments

  • CardList Example 2.zip
    116.4 KB · Views: 111
Last edited:
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Dear Mr. Mangojack, Many thanks .It work well, Thanks

I have uploaded an edited sample .
I mistakenly declared the panels as Panels instead of B4XViews , which allows direct access to panel Views properties.
 

Attachments

  • CardList Example 3.zip
    116.4 KB · Views: 84
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
PS: Apologies on behalf of Mr. DonManfred & Mr. Ronell not replying ... I believe they were at the Races .
been busy this past few days.. you know some annoying clients to deal with :confused: but thanks anyways for updating and solving the thread ..
 
Upvote 0
Top