Android Question Disable Item in xCustomListView

bocker77

Active Member
Licensed User
Longtime User
Is it possible to disable an item in a xCustomListview? I have looked in the forum for an answer but am not able to locate a solution. I tried this code but it doesn't disable it and I can still click on it.

B4X:
Sub EnableAll(p As Panel, Enabled As Boolean)
   For Each v As View In p
      If v Is Panel Then
         EnableAll(v, Enabled)
      Else
         v.Enabled = Enabled
      End If
   Next
End Sub

And of course a simple p.Enable = False doesn't work.

I could just remove the item but was wanting to still have it in the list for the user to few but not be able to do anything with it. Thanks in advance to those who respond.

BTW - this forum is awesome. I am usually able to find answers to most of my problems. Many thanks to those persons that take the time to give solutions to us neophytes.
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Try changing the For... loop to
B4X:
   For Each v As View In p.GetAllViewsRecursive
      If v Is Panel Then
         v.Enabled = Enabled
      End If
   Next
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
I've not used xcustomlistview, but this should work.
Looking at Erels example code, I believe that even if an item is there you can always click on it. The trick is to disable the panel (item) in the following way.
B4X:
    clv1.GetPanel(0).Enabled = False '0 is the first item, 1 is second item etc

Now in the following sub, check to see if the item is enabled or not. If the item is enabled then execute your code. You do not need an Else option, if you had an Else option it would just be Return.
B4X:
Sub clv1_ItemClick (Index As Int, Value As Object)
    If clv1.GetPanel(Index).Enabled Then
        Activity.Title = Value
        clv1.AsView.BringToFront
    End If
End Sub

I've just quickly utilised Erels example code, so it should work correctly. When you tap the first row, nothing should happen.

Enjoy...
 
Last edited:
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Thank you both for your suggestions but sad to say the click is still registering. I tried to disable all of the views on the clv and panel but with no luck.

B4X:
        CLV.GetPanel(0).Enabled = False
        CLV.GetPanel(1).Enabled = False
        CLV.GetPanel(2).Enabled = False
        CLV.GetPanel(3).Enabled = False
        CLV.GetPanel(4).Enabled = False
        Dim btnTemp As Button
        btnTemp = p.GetView(0)
        btnTemp.Enabled = False
        btnTemp = p.GetView(1)
        btnTemp.Enabled = False
        btnTemp = p.GetView(2)
        btnTemp.Enabled = False
        btnTemp = p.GetView(3)
        btnTemp.Enabled = False    
        Image.Enabled = False
        p.Enabled = False
[code]

It seems to be quite odd that this cannot be accomplished. If anyone else would like to take a crack at this it would be greatly appreciated.

Thanks
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Sure I can do that but basically it is two xCustomListViews attached to a TabHost (two tabs) with a Panel hosting them. I will put something together for you to try.

Thanks
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Manfred,

Attached is the zip file that the IDE created from the File menu. I hope that this is good enough to test with. The project includes the xCustomListView class.

Thanks again,
Greg
 

Attachments

  • xCustomListViewItemClick.zip
    17.2 KB · Views: 243
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Peter,

I am not quite sure I know what you are getting at. If I misunderstood you my bad. As stated earlier what I would like to happen is the clv item to work just like any other control or view that is disabled. The item is dimmed and if the user selects it it acts disabled.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
B4X:
'Row 0
    clv1.GetPanel(0).Enabled = False '0 is the first item
    clv1.GetPanel(0).Color = 0x7F644747 'Background color
    clv1.GetPanel(0).GetView(0).TextColor = 0x7F535353 'Text color
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
OK I understand now. I check to see if it is disabled on subsequent clicks of that item and if so I return without doing anything. Thanks to all that took the time to look into this for me especially Peter who gets the Kewpie doll for the correct answer.

Here is the code along with Peters from above that resolved my issue.

B4X:
Sub clvArmy_ItemClick (Index As Int, Value As Object)
    ' Shattered Unit cannot be used
    If iArmyTurn = 1 Then
        If clvArmy1.GetPanel(Index).Enabled = False Then Return
    Else If iArmyTurn = 2 Then
        If clvArmy2.GetPanel(Index).Enabled = False Then Return
    End If

...
 
Upvote 0
Top