CustomListView - A flexible list based on ScrollView

Status
Not open for further replies.

Jaames

Active Member
Licensed User
Longtime User

Attachments

  • ss3.jpg
    ss3.jpg
    13.2 KB · Views: 1,599
  • ss1.jpg
    ss1.jpg
    12.2 KB · Views: 1,571
  • ss2.jpg
    ss2.jpg
    19.6 KB · Views: 1,640

Jaames

Active Member
Licensed User
Longtime User
Since Erel does not answering me i'll post my solution for this problem :)

I just added another sub and instead .Clear i call .Clear1 SUB in Erel's CustomListView as is below:

B4X:
Public Sub Clear1
   For x = 0 To panels.Size -1
      Dim removePanel As Panel
      removePanel = panels.Get(x)
      removePanel.RemoveView
    Next
    items.Clear
   panels.Clear
   sv.Panel.Height = 0
   sv.Invalidate

End Sub

Cheers
 

BarrySumpter

Active Member
Licensed User
Longtime User
Very cool.

Not much needed to change my ScrollView to a Custom List View.

What a relief.

Really enjoying b4a.

Thanks to all who have contributed to make b4a so brilliant!

-----

I have 4 panels.

The last panel has an edit text at the bottom.

The edit text is 3 text lines high.

In portriat, I click the edit text.

The keyboard pops up and the edit text is scrolled
to where only one line of edit text is visible.

No prob since word wrap and kb crlf scrolls the edit text up to the next line.

But the android edit icon pointer
( the green colored house shaped pointer )
never appears.

If I turn to landscap, and click the edit text,
the edit text is scrolled to the very top with all three text lines visible
with the android edit icon pointer appearing properly.

Adding 50%y to the last panel size solves the issue in portriate mode.

B4X:
    clv1.Add(pnlStatus, pnlStatus.Height + 50%y, "Item 4")
Just thought the author would want to know and help others who might have the same issue.
 

bluedude

Well-Known Member
Licensed User
Longtime User
Getting the correct view

Hi,

I think this custom scrollview is great but I have a question. I have layout with 4 views and one of them is a checkbox.

In your sample you do something like this:

Dim lbl As Label
Dim chk As CheckBox
lbl = pnl.GetView(0)
chk = pnl.GetView(2)
lbl.Text = "Clicked!"
Msgbox("Item value: " & clv1.GetValue(itemIndex) & CRLF & "Check value: " & chk.Checked, "")

How do I know which index a view has in a layout? I want to get to my checkbox value but i'm not sure which index the view has.

Cheers.
 

Informatix

Expert
Licensed User
Longtime User
Hi,

I think this custom scrollview is great but I have a question. I have layout with 4 views and one of them is a checkbox.

In your sample you do something like this:

Dim lbl As Label
Dim chk As CheckBox
lbl = pnl.GetView(0)
chk = pnl.GetView(2)
lbl.Text = "Clicked!"
Msgbox("Item value: " & clv1.GetValue(itemIndex) & CRLF & "Check value: " & chk.Checked, "")

How do I know which index a view has in a layout? I want to get to my checkbox value but i'm not sure which index the view has.

Cheers.

Try the CheckList class. It should ease your checkbox management.
 

bluedude

Well-Known Member
Licensed User
Longtime User
Interesting but not really what I'm looking for in this specific case. I just need to know how I can get an Index of a view. The getView method needs to have a view Index.
 

bluedude

Well-Known Member
Licensed User
Longtime User
I wish I knew that :) Long time ago that i added these. Wouldn't it be great to add the Index to the properties in the designer? So if you click on a view that it shows the Index.
 

androh

Member
Licensed User
Longtime User
UpdateAt

Hi,
I did a small add-on for customlistview that "UpdateAt"
It removes panel and inserts new panel.

B4X:
'Updates a custom item at the specified index.
Public Sub UpdateAt(Index As Int, Pnl As Panel, ItemHeight As Int, Value As Object)    
   
   Dim removePanel, p As Panel
   removePanel = panels.Get(Index)
   items.RemoveAt(Index)
   panels.RemoveAt(Index)
   removePanel.RemoveView
   
   
   Dim sd As StateListDrawable
    sd.Initialize
    sd.AddState(sd.State_Pressed, pressedDrawable)
    sd.AddCatchAllState(Pnl.Background)
   
   'create another panel to handle the click event
   Dim p As Panel
   p.Initialize("panel")
   p.Background = sd
   Dim cd As ColorDrawable
   cd.Initialize(Colors.Transparent, 0)
    Pnl.Background = cd
   p.AddView(Pnl, 0, 0, sv.Width, ItemHeight)
   p.Tag = Index   

   Dim top As Int
   If Index = 0 Then
      top = dividerHeight
   Else
      Dim previousPanel As Panel
      previousPanel = panels.Get(Index - 1)
      top = previousPanel.top + previousPanel.Height + dividerHeight
   End If

   items.InsertAt(Index, Value)
   panels.InsertAt(Index, p)
   sv.Panel.AddView(p, 0, top, sv.Width, ItemHeight)

End Sub
 
Last edited:

maleche

Active Member
Licensed User
Longtime User
This is close to what I'm looking for!

How is this modified to add spinners in the scrollview?

Wow!
Doyle
 

maleche

Active Member
Licensed User
Longtime User
Not clear on "add a panel as the item..." do you mean panel1.add (spinner1,x,y,h,w)?
Thanks.
 

sorex

Expert
Licensed User
Longtime User
Hello,

I used this class and it appeared to work fine.

Although I bumped into an issue that I can't seem to solve.

When I set dimensions to lets say 100%x and 200, but the items only cover y=100
I get this gray background under the list items.

I first thought it was because of the panel nesting in this structure activity>panel>panel>panel>clv_list but all panels have a black background.

setting the defaulttextbackground doesn't change anything either, but I think this is for list items only right?
 
Status
Not open for further replies.
Top