CustomListView - A flexible list based on ScrollView

Status
Not open for further replies.

sorex

Expert
Licensed User
Longtime User
scrollview is my panel?

mycode is currently this:

B4X:
clvRegions.Initialize(Me, "clvRegions")
clvRegions.DefaultTextBackgroundColor=Colors.Black 
pnlRegions.Color=Colors.Black 
pnlregions.AddView(clvRegions.AsView, 0, 0, pnlRegions.Width, pnlRegions.Height)

Just checked the initial example and it has the same behaviour, uncovered list area is white/grey altho the panel and activity is set to black.
 
Last edited:

sorex

Expert
Licensed User
Longtime User
ok, I use this as a workaround after filling the list

B4X:
If regionpubs.Size*50dip<100%y-(40+40) Then
   pnlRegionPubs.Height=(regionpubs.size)*50dip
Else
   pnlRegionPubs.Height=100%y-(40+40)
End If

if someone has a better solution I'll be glad to hear/read it.
 

sorex

Expert
Licensed User
Longtime User
Like I said in one of my previous posts you can do this:

1. download the example from Erel on page 1 of this thread
2. change the list items count from 20 to 5
3. run it

you'll see some gray box under the 5th listitem (if you set the background and panel to black)
 

klaus

Expert
Licensed User
Longtime User
To change this color you need to change it in the Class code:
B4X:
Public Sub Initialize (vCallback As Object, vEventName As String)
    sv.Initialize2(0, "sv")
    items.Initialize
    panels.Initialize
    dividerHeight = 2dip
    EventName = vEventName
    CallBack = vCallback
'    sv.Color = 0xFFD9D7DE 'this sets the dividers color
    sv.Color = Colors.Yellow 'this sets the dividers color
I tried with yellow. But this is also the color of the separator lines.

Best regards.
 

QLogic

Member
Licensed User
Longtime User
Minor question... How do I go about changing the font size of the texts in one customlistbox?

I.E. first node has a size 10 font, second node has a size 8 font.

Thanks.

EDIT: Nevermind, I figured it out by editing the class file :)
 
Last edited:

sorex

Expert
Licensed User
Longtime User
Klaus: thanks, I will have a look at that, but it does mean that my seperator lines will be black then?

maybe that panel resize should be added there since you feed the panel dimensions to the class anyway.

Qlogic: You schould do this in the code where you add your elements.

if you have 2 lists with different look/layout you'll have an issue if you use the edit class method ;)
 

QLogic

Member
Licensed User
Longtime User
Klaus: thanks, I will have a look at that, but it does mean that my seperator lines will be black then?

maybe that panel resize should be added there since you feed the panel dimensions to the class anyway.

Qlogic: You schould do this in the code where you add your elements.

if you have 2 lists with different look/layout you'll have an issue if you use the edit class method ;)

It was actually just 3 lines of code I had to change in the class file to make it work.

Brought to you by the Google Galaxy Nexus. It IS better than the iPhone 5.
 

gawie007

Member
Licensed User
Longtime User
CustomListView memory limitation

Hi Erel,
This is very useful - Thank You!

I replaced your CheckBox with an ImageView.
I tested this first on my Samsung GT1500 (I use it to test my programs backward compatibility.) and found that it would force close. This worked fine on my HTC Desire Z however.
I assumed that it was the targetSdkVersion = "14" in the manifest file so I changed it to "8" (Eclaire on the Samsung)- No difference observed.

I then built a new project and copied all the relevant code and files. The manifest only had minSdkVersion="4" - no targetSDKVersion.
The same problems were encountered.

On line 30 in the main module you create 1000 of these panels. I reduced this to 100 and everything works fine now, even in the original example.
It seems to me that each time the image is drawn, it utilises memory even though the drawings are identical and if the phone has insufficient memory, it force closes.

The images I am using are essentially used as Buttons.
Would it save memory if I placed the image on a Button View rather than an ImageView?
In the list that I am creating, I will have many duplicate images to click on.

Kind regards
Gavin
 

Informatix

Expert
Licensed User
Longtime User
It seems to me that each time the image is drawn, it utilises memory even though the drawings are identical and if the phone has insufficient memory, it force closes.

The images I am using are essentially used as Buttons.
Would it save memory if I placed the image on a Button View rather than an ImageView?
In the list that I am creating, I will have many duplicate images to click on.

If you want to avoid an OOM (Out of Memory exception) with duplicate images, declare these images as bitmaps or bitmapdrawables (it doesn't matter) in Globals and load them in Activity_Create outside the loop where you assign them to the ImageView( in this case, outside of CreateListItem). If you use LoadBitmap in the loop, an individual image will be created with each iteration.
 

gawie007

Member
Licensed User
Longtime User
CustomListView memory limitation

Thank you Informatix!
Spot on!
Loads 4000 items now then force closes.
Loads and runs 3000 items.
Well exceeds the specs of 1000 to 2000 items.
I have learnt a valuable lesson today - Thank You!

Kind regards
Gavin
 

sorex

Expert
Licensed User
Longtime User
Klaus,

that scrollview color solution worked fine.

but now I have another issue :)

I want some gaps between my items.

option 1: just make the added item higher

issue: when you click on it you get this light blue highlight color flash. I tried adding a black label under my text/gradient label what should cover the gap size (it's even bigger) but I still see a 1 or 2 pixel highlight flash. (even when I set the divider size to 0 in the class)



option 2: set the divider size

issue: works but since the divider is added before the first item you need to divide the devider size from the .top value, works fine with a list that fits on the screen but will generate other issue when it will start scrolling (items will appear to high on the screen)


I'm fine with option 1 so I was wondering if you could change the highlight color in some way in this class to black instead of light blue ?
 
Last edited:

sorex

Expert
Licensed User
Longtime User
Your class is too advanced for me and my project at the moment but it will become usefull when I'm getting used to all this tho.

I found the solution for my issue tho.

I commented this line in the class

'sd.AddState(sd.State._Pressed, pressedDrawable)
 

maleche

Active Member
Licensed User
Longtime User
Ok, I had to modify the code to include CheckBox or Spinner based on my data. The checkbox is easy, but when adding a spinner, I had to determine how many data points to add to the dropdown. I've got it to work using 'trial and error'. I'm not to sure I understand the panel in a panel or view in a panel routine here.

Attached is a screen shot of one dropdown selection for my OBD routines.

I've got a lot to learn!

Thanks for the start!
 

Attachments

  • PrefScreen.png
    PrefScreen.png
    66.2 KB · Views: 1,000

macnlkc

Member
Licensed User
Longtime User
A couple of questions...

1) I have two lists. List one is an index and list two is a detail list for each index item. I want to be able to select an index item from the first list and only show detail items in list two that are tied to the index list item selected.

2) How do you create items in the list that have uniform spacing for each item?

Thanks. I know these are probably simple questions but I am still very new to this development.

:sign0104:
 

macnlkc

Member
Licensed User
Longtime User
How would I set up the two lists? Do these need to be arrays or can you do it with list and then iterate through list one and select list two items from it? I guess I could do it with arrays but thought that might be slower and wouldn't work with the CustomListView controller.

I attempted to take a picture and got an error that stated, "Cannot take screenshot from device connected with B4A-Bridge." It is a tablet running at 800x600 in landscape mode. Is there a way to take it from the tablet directly?
 
Status
Not open for further replies.
Top