' in Class_Globals
Public catdialog As B4XDialog
Private edt1 As EditText
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("category_layout")
B4XPages.SetTitle(Me,"Lists_textfiles_notes - Category")
catdialog.Initialize(Root)
catdialog.PutAtTop = True
catdialog.BackgroundColor = Colors.LightGray
catdialog.BodyTextColor = Colors.Blue
End Sub
private Sub setup_dialog(strlayout As String,lbltext As String) As Panel
Dim pnl As B4XView = xui.CreatePanel("")
pnl.SetLayoutAnimated(0, 0, 0, 340dip, 150dip)
pnl.LoadLayout(strlayout)
Dim lbl As Label
lbl.Initialize("")
lbl.Text = lbltext
lbl.TextSize = 20
lbl.TextColor = Colors.Black
lbl.Color = Colors.LightGray
pnl.AddView(lbl,0,0,340dip,50dip)
Return pnl
End Sub
Sub btn2_Click
Dim pnl1 As Panel = setup_dialog("category_dialog","Add category")
Wait For (catdialog.ShowCustom(pnl1, "OK", "", "CANCEL")) Complete (Result As Int)
If Result = xui.dialogResponse_Positive Then
If edt1.Text <> "" Then
clv2.AddTextItem(edt1.text,edt1.text)
If clv2.Size > 0 Then
save_list
End If
End If
End If
End Sub
Sub clv2_ItemClick (Index As Int, Value As Object)
Dim pnl1 As Panel = setup_dialog("category_dialog","Edit/Delete category")
Dim rs1 As ResumableSub = catdialog.ShowCustom(pnl1, "SAVE", "DELETE", "CANCEL")
edt1.Text = clv2.GetValue(Index)
Wait For (rs1) Complete (Result As Int)
If Result = xui.dialogResponse_Positive Then
If edt1.Text <> "" Then
clv2.RemoveAt(Index)
clv2.InsertAtTextItem(Index,edt1.text,edt1.text)
End If
else if Result = xui.dialogResponse_Negative Then
clv2.RemoveAt(Index)
End If
If clv2.Size > 0 Then
save_list
End If
'ToastMessageShow("item at position " & Index & " has value " & Value,True)
End Sub