Hi
What is the correct way to delete items in the list?
I have prepared the following version but it does not work well
Each time I delete an option, the indexes change
thank you
What is the correct way to delete items in the list?
I have prepared the following version but it does not work well
Each time I delete an option, the indexes change
thank you
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
'#BridgeLogger: True
Sub Process_Globals
Public ActionBarHomeClicked As Boolean
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim pm As B4XPagesManager
pm.Initialize(Activity)
End Sub
'Template version: B4A-1.01
#Region Delegates
Sub Activity_ActionBarHomeClick
ActionBarHomeClicked = True
B4XPages.Delegate.Activity_ActionBarHomeClick
ActionBarHomeClicked = False
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
Return B4XPages.Delegate.Activity_KeyPress(KeyCode)
End Sub
Sub Activity_Resume
B4XPages.Delegate.Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
B4XPages.Delegate.Activity_Pause
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
B4XPages.Delegate.Activity_PermissionResult(Permission, Result)
End Sub
Sub Create_Menu (Menu As Object)
B4XPages.Delegate.Create_Menu(Menu)
End Sub
#if Java
public boolean _onCreateOptionsMenu(android.view.Menu menu) {
processBA.raiseEvent(null, "create_menu", menu);
return true;
}
#End If
#End Region
'Program code should go into B4XMainPage and other pages.
B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Dim PageClv1 As PageClv
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
PageClv1.Initialize
B4XPages.AddPage("PageClv1",PageClv1)
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
B4XPages.ShowPage("PageClv1")
End Sub
B4X:
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private CustomListView1 As CustomListView
End Sub
'You can add more parameters here.
Public Sub Initialize As Object
Return Me
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
'load the layout to Root
Root.LoadLayout("LayoutPageClv")
For i=0 To 99
Dim XCustomViewItem1 As XCustomViewItem
XCustomViewItem1.Initialize(Me,"XCustomViewItem1")
XCustomViewItem1.DesignerCreateView(CustomListView1.GetBase.Width,i)
CustomListView1.Add(XCustomViewItem1.mBase ,i)
Next
End Sub
Sub Remove_XCustomViewItem1 (i As Int)
Log("del index => "& i)
CustomListView1.RemoveAt(i)
End Sub
B4X:
#DesignerProperty: Key: BooleanExample, DisplayName: Show Seconds, FieldType: Boolean, DefaultValue: True
#DesignerProperty: Key: TextColor, DisplayName: Text Color, FieldType: Color, DefaultValue: 0xFFFFFFFF, Description: Text color
Sub Class_Globals
Private mEventName As String 'ignore
Private mCallBack As Object 'ignore
Public mBase As B4XView
Private xui As XUI 'ignore
Public Tag As Object
Dim LabelDel As Label
Dim LabelDel2 As Label
End Sub
Public Sub Initialize (Callback As Object, EventName As String)
mEventName = EventName
mCallBack = Callback
Dim mBase As B4XView = xui.CreatePanel("")
End Sub
'Base type must be Object
'Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
Public Sub DesignerCreateView (WidthView As Int,index As Int)
' mBase = Base
mBase.Color=Colors.ARGB(255,Rnd(0,255),Rnd(0,255),Rnd(0,255))
mBase.Width=WidthView
mBase.Height=25%y
' Tag = mBase.Tag
' mBase.Tag = Me
' Dim clr As Int = xui.PaintOrColorToColor(Props.Get("TextColor")) 'Example of getting a color value from Props
LabelDel.Initialize("LabelDel")
LabelDel.Tag=index
LabelDel.Text="Click Del index="&index
LabelDel.Gravity=Bit.Or(Gravity.CENTER_HORIZONTAL,Gravity.CENTER_VERTICAL)
LabelDel.Color=Colors.Red
mBase.AddView(LabelDel,5%x,5%y,30%x,10%y)
LabelDel2.Initialize("LabelDel2")
LabelDel2.Tag=index
LabelDel2.Text=index
LabelDel2.Gravity=Bit.Or(Gravity.CENTER_HORIZONTAL,Gravity.CENTER_VERTICAL)
LabelDel2.Color=Colors.Yellow
mBase.AddView(LabelDel2,0%x,0%y,5%x,5%x)
End Sub
Private Sub Base_Resize (Width As Double, Height As Double)
End Sub
Sub LabelDel_Click
Log("who to delete this index from Clv?")
Dim b As Label
b = Sender
b.Color=Colors.Yellow
Log(b.Tag)
b.Text = "who to delete this index from Clv?"
CallSub2(mCallBack,"Remove_"&mEventName,b.Tag)
End Sub