Android Question xCustomListView and MultiSelect

MarcoRome

Expert
Licensed User
Longtime User
Hi all.
There is the possibility of making multiple selections. For example:
XCustomlistiview has 4 records.
Select the 1 and 3 records, and i see both the colored records in green
Thank you
Marco
 

DonManfred

Expert
Licensed User
Longtime User
It is up to you to go over the CLV and paint panel 0 and 2 in another color after the user clicked on them.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
If you have in your layer position 0 a Panel, position 1 a label, etc. and you want color in RED the panel in position 0 the code is:

B4X:
Sub clv_ItemClick (Index As Int, Value As Object)
Dim pp As B4XView = clv.GetPanel(Index).GetView(0)
    If pp.Color = Colors.Red Then
        pp.Color = Colors.White
    Else
        pp.Color = Colors.Red
    End If
End Sub
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
It would have been better to store the state in the Value object, maybe with a custom type.

1. It will not break when you change the UI.
2. It will be easier to save it.

mmhh..can you give me a little example
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Type MyItemState (Selected As Boolean) 'and more fields as needed

Add an instance of this type for each item, when you add items to CLV.

B4X:
Sub clv_ItemClick (Index As Int, Value As Object)
Dim state As MyItemState = Value
state.Selected = Not(state.Selected)
Dim pp As B4XView = clv.GetPanel(Index).GetView(0)
    If State.Selected = False Then
        pp.Color = Colors.White
    Else
        pp.Color = Colors.Red
    End If
End Sub
 
Upvote 0

Claudio Oliveira

Active Member
Licensed User
Longtime User
Hi, @MarcoRome
I'm working on this at this very moment! ;)
Some funcionalities have been implemented inside xCustomListView, such as:
- Allow (or not) selection (multi selection is implied) (available in designer and programatically);
- Chose whether to show or not a check mark in the upper right corner of the selected item panel (available in designer and programatically);
- Choose typeface, character and color of such a check mark (available in designer and programatically);
- Select and deselect one or all items programatcally;
- Get a list of all selected items panels;
- Get the number of selected items;
- ItemLongClick event implemented;
- ItemSelected and ItemDeselected implemented;

It's 2:01AM here, I just finished testings and... so far, so good!

My ToDo list now is:
- Implement a SelectItems(ItemList as List) sub, and
- Comment and clean up code.

This work is being done based on xCustomListView v1.50, and all original functionalities of the class remain unaltered.

Hopefully tomorrow I'll have the job done, IF nothing else comes to my mind meanwhile... ;)

The picture attached shows an example of how it looks...

Regards!
Claudio
 

Attachments

  • Screenshot_2018-02-02-01-52-56_temp.png
    Screenshot_2018-02-02-01-52-56_temp.png
    142.9 KB · Views: 417
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Hi, @MarcoRome
I'm working on this at this very moment! ;)
Some funcionalities have been implemented inside xCustomListView, such as:
- Allow (or not) selection (multi selection is implied) (available in designer and programatically);
- Chose whether to show or not a check mark in the upper right corner of the selected item panel (available in designer and programatically);
- Choose typeface, character and color of such a check mark (available in designer and programatically);
- Select and deselect one or all items programatcally;
- Get a list of all selected items panels;
- Get the number of selected items;
- ItemLongClick event implemented;
- ItemSelected and ItemDeselected implemented;

It's 2:01AM here, I just finished testings and... so far, so good!

My ToDo list now is:
- Implement a SelectItems(ItemList as List) sub, and
- Comment and clean up code.

This work is being done based on xCustomListView v1.50, and all original functionalities of the class remain unaltered.

Hopefully tomorrow I'll have the job done, IF nothing else comes to my mind meanwhile... ;)

The picture attached shows an example of how it looks...

Regards!
Claudio
Well done Claudio ;)
 
Upvote 0

Claudio Oliveira

Active Member
Licensed User
Longtime User
Hey guys

Well... A “bit” later than I promised, but here I am. :D
Something else did come to my mind: enabling / disabling individual panels, and this took me some more time to code, comment and stuff…

xMultiSelCustomListView is based on Erel's awesome xCustomListView class version 1.50 which I've modified to implement (multi)selection/deselection and (multi)enabling/disabling individual panels.
I decided to work on this to meet my personal needs, but I reckon this thread shows this might be something other developers have been waiting for, so here we are.
I’ve tested this code thoroughly and it’s fully functional, still there might have one bug or another in it. I really do hope not indeed! :D

Some notes on these features:
  • Like most Android applications, once you long click a panel to select it, you start the selection process, so clicking or long clicking other panels you toggle them selected/unselected. Once there are no more selected panels, the selection process ends and will start when a new long click occurs.
  • If selection is disabled, panels can still be selected/deselected by code and the selection ItemSelected / ItemDeselected events will still be raised.

I’m sure I can improve code, comments and certeinly performance. I will surely do it next, but for now it is totally usable. Work's still under way...
Feedbacks, ideas, critics and wishes will be highly appreciated! ;)

Hope you enjoy :D

Greetings!


xMultiSelCustomListView

Based on Erel's xCustomListView v1.50

Version:
1.00

All original events, functions and properites remain active

o Events added:
  • ItemLongClick (Position As Int, Value As Object)
  • ItemSelected (Position As Int, Value As Object)
  • ItemDeselected (Position As Int, Value As Object)
  • ItemEnabled (Position As Int, Value As Object)
  • ItemDisabled (Position As Int, Value As Object)

o Functions added:
  • DeselectAll As Int
  • DeselectPanel (Index As Int) As Object
  • DeselectPanelList (ItemList As List) As List
  • DisablePanel( Index As Int ) As Object
  • DisablePanelList(PanelList As List) As List
  • EnablePanel( Index As Int )
  • IsPanelEnabled(Index As Int) As Boolean
  • IsPanelSelected(Index As Int) As Boolean
  • SelectAll As Int
  • SelectPanel(Index As Int)
  • SelectPanelList(IndexList As List) As List

o Properties added:

  • CheckCharacter( CheckChar As String ) [write only]
  • CheckColor(Color As Int) [read / write]
  • CheckTypeface( CheckType As Typeface ) [write only]
  • DisabledColor As Int [read / write]
  • SelectionEnabled As Boolean [read / write]
  • SelPanels As List [read only]
  • SelSize As Int [read only]
  • ShowCheck As Boolean [read / write]
 

Attachments

  • xMultiSelCustomListView.bas
    33.9 KB · Views: 268
Upvote 0

Claudio Oliveira

Active Member
Licensed User
Longtime User
Sorry!
Wrong .bas file! :confused:
Here the right one...
 

Attachments

  • xMultiSelCustomListView.bas
    34.3 KB · Views: 280
Upvote 0

Claudio Oliveira

Active Member
Licensed User
Longtime User
I've created a new thread on this subject with a new and more thoroughly tested class version.
Regards
 
Upvote 0
Top