Android Question CustomListView and BetterDialogs problem...

ciprian

Active Member
Licensed User
Longtime User
Hi there.

I'm having some trouble with my project and don't have the experience to find the solution by my self...so please show me the way.
When i'm doing a longclick on labels, the betterdialogs are opening a dialog to change label text But i'm having this error.

Capture.PNG

I atached my project and the error i have.
 

GMan

Well-Known Member
Licensed User
Longtime User
As the log shows in the 1st line an object should be initialized first....it is a view that you call
B4X:
YourView.initalize()
 
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
No, latest before you call the view from out your app you has to init it once
Didnt have a look to your code yet....
 
Upvote 0

ciprian

Active Member
Licensed User
Longtime User
I am using some part of the customlistview exemple, and i added the BetterDialogs library.
The error i have, it's inside the class...
B4X:
Public Sub GetItemFromView(v As View) As Int
    Dim r As Reflector
    Dim parent, current As Object
    parent = v 'it's here i'm getting the error
    Do While (parent Is Panel) = False OR sv.Panel <> parent
        current = parent
        r.Target = current
        parent = r.RunMethod("getParent")
    Loop
    v = current
    Return v.Tag
End Sub

Not saying the class is not good....it's briliant, but in my case, i have this problem...i'm sure it's my fault...on how i'm using it.
 
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
if I switch to debug mode the error occurs on the following line:
B4X:
'Returns the index of the item that holds the given view.
Public Sub GetItemFromView(v As View) As Int
    Dim r As Reflector
    Dim parent, current As Object
    parent = v                                              ' HERE OCCURS THE ERROR
    Do While (parent Is Panel) = False OR sv.Panel <> parent
        current = parent
        r.Target = current
        parent = r.RunMethod("getParent")
    Loop
    v = current
    Return v.Tag
End Sub

so, same place as you.
But cant get it work, too

Initalizing v (in the block before) dont work...
 
Upvote 0

ciprian

Active Member
Licensed User
Longtime User
I've allready tried that.
Actually, as i'm a newbie....THE Newbie....i can say...most errors it's in my code... I'ts been only 3 months since i have started to create apps...i'm learning all by my self with the forum's helps and exemples. Never studied at school, or somewhere else.....
That's why i'm having always problems...i'm not such a good developer....i just wanna learn, progress....

Thank you anyway.
 
Upvote 0

ciprian

Active Member
Licensed User
Longtime User
I was using the same BetterDialog library but not with the customlistview class, i was having a panel with labels in my layout.
I was doing the same lbl_LongClick action, with the same code...and it worked.
The problem is that when i replaced the panel with the customlistview, it's happening something...don't know what...
 
Upvote 0

ciprian

Active Member
Licensed User
Longtime User
To produce the first error, you must longclick on a label, introduce a text into the mesagebox and click ok. the error is in the debug mode.
I atached my project as you sait. (export as zip).
 

Attachments

  • project.zip
    20.1 KB · Views: 184
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm getting the following error:
main_lbl_longclick (java line: 518)
java.lang.ClassCastException: flm.b4a.betterdialogs.BetterDialogs$InputParams cannot be cast to android.view.View
at b4a.example.main._lbl_longclick(main.java:518)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$2.onLongClick(ViewWrapper.java:73)
at android.view.View.performLongClick(View.java:4276)
at android.widget.TextView.performLongClick(TextView.java:8236)
at android.view.View$CheckForLongPress.run(View.java:17700)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
java.lang.ClassCastException: flm.b4a.betterdialogs.BetterDialogs$InputParams cannot be cast to android.view.View
[/code]
 
Upvote 0

ciprian

Active Member
Licensed User
Longtime User
I think i found the error.... don't know what i've done this morning, but i modified this :
B4X:
Sub lbl_LongClick
    Dim index As Int
    index = clv1.GetItemFromView(Sender)
    Dim pnl As Panel
    pnl = clv1.GetPanel(index)
    Dim lbl As Label
    lbl= pnl.GetView(0)
  
'    Msgbox(clv1.GetValue(index), "Rename ?")
    'Message box
    Dim DR As Int
    Log("DR=" & DR)
    Dim IP As BD_InputBoxParams
    IP.Initialize
    IP.Question = "<I>Rename Relais 1? </I>"
    IP.QuestionTextSize = 18
    IP.SpaceBetween = 4dip
    IP.InputTextSize = 24
    IP.InputType = IP.INPUT_TYPE_TEXT_WITH_CAPS
    IP.Gravity = Gravity.CENTER_VERTICAL + Gravity.CENTER_HORIZONTAL
    IP.ValidationCallback = "Input_Validation"
    IP.WithSuggestions = True
    DR = BD.InputBox("New Name", IP, "OK", "Cancel", "", LoadDrawable("ic_menu_edit"))
    Log("DR=" & DR)
    If DR = DialogResponse.POSITIVE Then
        Log(IP.Answer)
        Log(IP.CompactAnswer)
        lbl.Text = IP.Answer
    Else
    End If
  
    Dim btnOK As Button
    btnOK.Initialize("")
    btnOK.Background = CreateStateListDrawable
    btnOK.Text = "<Font Color='Yellow'>O</Font>K"
    btnOK.TextColor = Colors.White

    Dim btnCancel As Button
    btnCancel.Initialize("")
    btnCancel.Text = "<Font Color='Yellow'>C</Font>ancel"
    btnCancel.TextColor = Colors.White
    btnCancel.Background = CreateStateListDrawable
End Sub

It seems to work. :)
 
Upvote 0
Top