B4J Code Snippet Disable TextItem in B4XPreferencesDialog

Sometimes we want to lock a TextItem from being editable. For example a primary key item.
B4X:
Dim sf As Object = PrefDialog.ShowDialog(Data, "OK", "CANCEL")
If RowId > 0 Then
    Dim pi As B4XPrefItem = PrefDialog.GetPrefItem("Item Code") ' <-- Disallow edit on Item Code
    PrefDialog.CustomListView1.AnimationDuration = 0
    If pi.ItemType = PrefDialog.TYPE_TEXT Then
        Dim pnl As B4XView = PrefDialog.CustomListView1.GetPanel(0)
        Dim ft As B4XFloatTextField = pnl.GetView(0).Tag
        ft.mBase.Enabled = False
    End If
End If

Wait For (sf) Complete (Result As Int)
References:
 

pliroforikos

Active Member
Licensed User
hi
i tried to do the same with Password field without success. Any idea please?

B4X:
    Dim sf As Object = prefDialog.ShowDialog(mData, "OK", "CANCEL")
'    If RowId > 0 Then
        Dim pi As B4XPrefItem = prefDialog.GetPrefItem("Password1") ' <-- Disallow edit on Item Code
        prefDialog.CustomListView1.AnimationDuration = 0
        If pi.ItemType = prefDialog.TYPE_PASSWORD Then
            Dim pnl As B4XView = prefDialog.CustomListView1.GetPanel(0)
            Dim ft As B4XFloatTextField = pnl.GetView(0).Tag
            ft.mBase.Enabled = False
        End If
'    End If

The error is the bellow

Error occurred on line: 435 (B4XMainPage)
java.lang.RuntimeException: Field: _mbase not found in: java.lang.String
at anywheresoftware.b4a.shell.Shell$FieldCache.getField(Shell.java:923)
at anywheresoftware.b4a.shell.Shell.getField(Shell.java:697)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.eParousies.b4xmainpage._setpin(b4xmainpage.java:610)
at b4a.eParousies.b4xmainpage._b4xpage_menuclick(b4xmainpage.java:580)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)

This is my json file
{
"Version": 1.65,
"Theme": "Light Theme",
"Items": [
{
"title": "Use Pin",
"type": "Boolean",
"key": "switch1",
"required": false
},
{
"title": "Password1",
"type": "Password",
"key": "Password1",
"required": false
},
{
"title": "Password2",
"type": "Password",
"key": "Password2",
"required": false
}
]
}
 
Top