Android Question Arrays and my Metal block!

aidymp

Well-Known Member
Licensed User
Longtime User
Hi just a little back ground, but as a child I had an illness and I forgot a lot of stuff, it also seems to hinder me today as I cannot grasp some principles!

I can use B4A and J just fine, BUT I do everything the simple way!

Im trying to rewrite my code, but cannot work out certain things due to this block!

Arrays! I understand the basics but cant visualise them making them hard for me to use, so i don't use them! and this is my major problem!

At present I hard code everything, meaning my programs work but are hard to change! a simple change like adding something in the middle of a list requires me to do a huge amount of work!

The basic idea is based on something like lets say playstore

So I have :

a url of my package
a name of my package
a screen shot of my package
a few more bits of info about my package!

currently I have all this hard coded in the app! i understand how I would do ONE! via a settings file or xml variant with tags. but I dont know how I could read a list of more than one and put all the info in the right place! (not that i dont know, more I cannot understand or get it to lock in my head)

So I am asking if someone could show me how to do this!?

file sample i would like to use

<url>http://myapp.com/app1</url>
<name>"app name"</name>
<imageurl>http://myapp.com/app1</imageurl>
<counter>1020</counter>
<someotherinfo>blah blah</someotherinfo>

now i could read this easy!

but if i added another record how would i read that?

<url>http://myapp.com/app2</url>
<name>"app name"</name>
<imageurl>http://myapp.com/app2</imageurl>
<counter>145020</counter>
<someotherinfo>blah blah</someotherinfo>

<url>http://myapp.com/app3</url>
<name>"app name"</name>
<imageurl>http://myapp.com/app3</imageurl>
<counter>1023420</counter>
<someotherinfo>blah blah</someotherinfo>



currently i add each item to a list, all in code, then i have a lot of code to determine the current item in the list. so if item number 10 is selected, I would have something like

B4X:
Case 10
            url="http://myapp.com/app1"

and so on, but as you can imagine (my list only has 40 items) and i like it in alphabetical order, So if i need to add something in the middle I have a lot of code to change.

Im not asking for you to write it, rather explain in some alternative way that my brain will absorb, or point to various examples that i can look at and try to understand.

Currently the code I am using to add to the list is about 10 lines but repeated 40 times! the code i use when the list is selected is also about 8 lines but also repeated about 40 times!

Anyone able to help at all! I have read and read many books on basic but as I say the mental block, will not let me visualise arrays.

If anyone can help i would be very grateful!

Thanks

Aidy
 

aidymp

Well-Known Member
Licensed User
Longtime User
Upvote 0

sorex

Expert
Licensed User
Longtime User
then you're on the right track.

just download the xml from a webserver, if it can't access it use the last one downloaded or the one initially added into your apk.

then you just need to update the xml.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
@aidymp

Everyone else is proposing optional ways of achieving what you need, which is great, but if I may be so bold, I will try to give you an easy to understand visualisation of what an array is, so that you can use in future apps.

Imagine an array as a huge cabinet you have in your workshop, and this cabinet has 10 drawers...

Dim cabinet(10) as array ' this is your cabinet with the 10 drawers.

Now, in the digital world, almost everything starts at 0 and not at 1, so your drawers are numbered from 0 to 9.

Imagine you want to put a sock in the 6th drawer, counting from 0, it becomes number 5.

Cabinet(5) = mySock 'here we PUT a sock in the drawer.

To retrieve the contents of a drawer, we do the opposite...

mySock = Cabinet(5)

This is the simplest explanation possible to a one dimension array...

Make a "let's explore arrays" test app... Post any other questions about it you may have, or if you prefer, PM me, and I'll help in any way I can...
 
Upvote 0
Top