Android Question Get All Items Values into Arrays

Khairy Abdelhamid

Member
Licensed 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
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
 

Khairy Abdelhamid

Member
Licensed 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
 

ronell

Well-Known Member
Licensed 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
 

mangojack

Well-Known Member
Licensed 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
    '............
 

Khairy Abdelhamid

Member
Licensed 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
 

DonManfred

Expert
Licensed User

Khairy Abdelhamid

Member
Licensed 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

Khairy Abdelhamid

Member
Licensed 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
 

mangojack

Well-Known Member
Licensed 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

Last edited:

ronell

Well-Known Member
Licensed 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 ..
 
Top