Android Question CustomDialog and updating listView

dexMilano

Active Member
Licensed User
Longtime User
Hello all,
I've a bit complex situation to manage

Scenario:
my records can be associated to a classification that is a hierarchy.
When I create a new record I need to define the classification, so I'm using a customDialog (abraham's libray) and in this dialog I created
a panel
a list view
a label for showing selection in the list view.

Now I need to click on the record in the list view to see thir children and update the label with the complete path.

But it is not working at all.
I've found a post where it is said that only button click can be captured out of the dialog.
Is this correct?

How can manage this situation if not with a customDialog?

Any suggestion will be welcome

TIA

dex
 

devlei

Active Member
Licensed User
Longtime User
I am assuming your records are being stored in a database:
  • When filling your listview use Listview.AddSingleLine2 so that the record ID can be obtained from the Listview_ItemClick event.
  • Use that record ID and the link ID (which you must have defined as part of your hierachy/classification) to query the database to obtain the data of the child record to update the label.
 
Upvote 0

dexMilano

Active Member
Licensed User
Longtime User
Maybe my explantion is not too clear.
The creation of the list with its item is ok.
The point is that, inside the custom dialog, I need to interact with the list and every interaction requires an update of the list itself.
I use the list to move in a hierarchy tree of objects (not files) so I list all of the children of a given node, then I tap over one of them and the list must be updated and show the list of children of the selected object and so on.
Obviously to do this I need to mange the "Click" event in the application but it seems this event is not forwarded to the Activity, so I cannot write a code to manage it.
Maybe I'm missing something.

TIA

dex
 
Upvote 0

dexMilano

Active Member
Licensed User
Longtime User
Thanks Erel,
just because the look and fill will be different from the modal dialog generated with the library, do you think it will not be feasible using the custom dialog or only difficult?
And if it is difficult how can be implemented?

Thanks

dex
 
Upvote 0

dexMilano

Active Member
Licensed User
Longtime User
Hello All,
I modified the list view creation so all information is in the list item, no need to update a label.
However the point now is that when I click the OK button the control goes to the calling procedure and anly when the calling procedure is ended, the selection of the listview (lv click) is fired.

Here the code

This is the calling of the customdialog
B4X:
....
lsv_Dia01.Initialize("lsvDia01")
    'lbl_Dia01.Initialize("")
    pnl.AddView(lsv_Dia01, 0dip, 0dip, 100%x, 100%y)
    init_lsvClsDia01
   
    cd.AddView(pnl, 400dip, 300dip) ' sizing relative to the screen size is probably best but...
    'pnl.SetLayout (0dip,0dip,500dip,250dip)
    retDialog = cd.Show("MP2 - My Personal Priorities", "OK", "Cancel", "", bmp_app)
    'ret_dia01 has the class_id value !!!!!!!!!!!!!!

    If retDialog = DialogResponse.POSITIVE AND ret_Dia01 <> currentAct.class_id Then
        't_strD = lbl_class.Text
        currentAct.class_id = retDialog
        lbl_class.Text = cls2breadcomb (ret_Dia01)
        ToastMessageShow("The class of the activity has been updated.", False)
    End If
....

This is the click on the list view

B4X:
Sub lsvDia01_ItemClick (Position As Int, Value As Object)
   
    ret_Dia01 = lsv_Dia01.GetItem (Position)
    Log("Dialog " & Value &"/"& ret_Dia01)
   
End Sub

It seems that
If retDialog = DialogResponse.POSITIVE ...
is executed before the
ret_Dia01 = lsv_Dia01.GetItem (Position)

How can I handle it?

I think I can use a calldelayed but not clear how to

TIA

dex
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I have not used that dialog, but considering the response of Erel:

It is not possible to handle events when a modal dialog is visible.

I believe that the procedure is not performed until you close the dialog.

I think the only solution is to create a custom dialog, with the "look & feel" of that (well, copy :))
 
Upvote 0

dexMilano

Active Member
Licensed User
Longtime User
I've found a solution for it.
I want to share it becasue it could be useful for others.
Any comment/improvement will be welcome

The basic idea is to move the management of return from dialog to the list click event code.
This can be done using global variable also for dialog return (ret_diaBtn01) and ending the sub soon after the return from custom dialog
Here the code

B4X:
Sub btn_changeClass_Click
' define the ChooseClass dialog using CustomDialog **************************************************
Dim cd As CustomDialog2
Dim t_strD As String
Dim pnl As Panel
' using also list as lsv_dia01 with complete path for classes

    pnl.Initialize("pnl")
    Dim bgnd As ColorDrawable
    bgnd.Initialize(Colors.Black, 0dip)
    pnl.Background = bgnd
  
    lsv_Dia01.Initialize("lsvDia01")
    'lbl_Dia01.Initialize("")
    pnl.AddView(lsv_Dia01, 0dip, 0dip, 100%x, 100%y)
    init_lsvClsDia01
  
    cd.AddView(pnl, 400dip, 300dip) ' sizing relative to the screen size is probably best but...
    'pnl.SetLayout (0dip,0dip,500dip,250dip)
    ret_DiaBtn01 = cd.Show("MP2 - My Personal Priorities", "OK", "Cancel", "", bmp_app)
     ' Execution go to the click over then list lsvDia01_ItemClick  !!!!!!!!!!
End Sub

B4X:
Sub lsvDia01_ItemClick (Position As Int, Value As Object)
  
    ret_DiaLst01 = lsv_Dia01.GetItem (Position)
  
    ' moved assignment code here for modal dialog event management
    If ret_DiaBtn01 = DialogResponse.POSITIVE AND ret_DiaLst01 <> currentAct.class_id Then
        't_strD = lbl_class.Text
        currentAct.class_id = ret_DiaLst01
        lbl_class.Text = cls2breadcomb (ret_DiaLst01)
        ToastMessageShow("The class of the activity has been updated." &CRLF& "Save changes!", False)
    End If
End sub


Some comment on it:
1) this solution cannot be generally available. In my case it is ok to have the dialog as the last step of sub. I think it could be common but not always feasible.

2) There is a small bug I don't know how to manage: if I select more items in the list (by mistake) only the first is managed the others are ignored.

dex
 
Upvote 0
Top