My code has Erel's costum listview.
(https://www.b4x.com/android/forum/t...xible-list-based-on-scrollview.19567/#content)
and I added Location manager v.1.1. I learningn geo coordinates from cell.
normaly only clistview in my code >>> work.
normaly only location manager in my code>>> work.
Same time working costumlistwev and Locationa manager.>> NOT work
it is broken when it works "Sub etiket_Click"
costum listwiew
(https://www.b4x.com/android/forum/t...xible-list-based-on-scrollview.19567/#content)
and I added Location manager v.1.1. I learningn geo coordinates from cell.
normaly only clistview in my code >>> work.
normaly only location manager in my code>>> work.
Same time working costumlistwev and Locationa manager.>> NOT work
it is broken when it works "Sub etiket_Click"
B4X:
#Region Project Attributes
#ApplicationLabel: example
#VersionCode: 1
#VersionName: start
'SupportedOrientations possible values: unspecified, landscape or portrait.
'#SupportedOrientations: unspecified
#SupportedOrientations: landscape
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: TRUE
#IncludeTitle: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim clv1 As control_view
Dim clv3 As control_view
Private Button1 As Button
Private CheckBox1 As CheckBox
Private Spinner1 As Spinner
Dim Location As LocationManager
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Location.Initialize("Location")
Activity.LoadLayout("L1")
End Sub
Sub clv3_ItemClick(Index As Int, Value As Object)
Log(Index & " = " & Value)
End Sub
Sub CreateListItem2(Text As String, Width As Int, Height As Int, phonelist As List) As Panel
Dim p As Panel
p.Initialize("")
p.Color = Colors.Black
Dim b As Button
b.Initialize("button") 'all buttons click events will be handled with Sub Button_Click
Dim chk As CheckBox
chk.Initialize("chk")
Dim lbl As Label
lbl.Initialize("etiket")
Dim spn As Spinner
Dim spn2 As Spinner
spn.Initialize("spn")
spn2.Initialize("spn2")
spn.AddAll(phonelist)
spn2.AddAll(Array As String("bey","hanım","ablacağım","abiciğim","kardeşim","kuzenim","yeğenim","amcacağım","dayıcığım","halacığım","teyzeciğim", "yengeciğim","dedeciğim","nineciğim","babananeciğim", "anneanneciğim"))
lbl.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
lbl.Text = Text
lbl.TextSize = 16
lbl.TextColor = Colors.White
b.Text = "Click"
'p.AddView( l - T w- h
p.AddView(chk, 5dip, 2dip, 50dip, Height - 4dip) 'view #0
p.AddView(lbl, 55dip, 2dip, 165dip, Height - 4dip) 'view #1
p.AddView(spn, 220dip, 2dip, 170dip, Height - 4dip) 'view #2
p.AddView(spn2, 390dip, 2dip, 150dip, Height - 4dip) 'view #3
Return p
End Sub
Sub Activity_Resume
Location.requestMobileLocation
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
' scrool vieww için hazırlanmış
' https://www.b4x.com/android/forum/threads/class-customlistview-a-flexible-list-based-on-scrollview.19567/#content
'https://www.b4x.com/android/forum/threads/scrollview-examples-summary.8423/#content
ProgressDialogShow("Rehberiniz okunuyor ve listeleniyor...")
DoEvents
'********************* SMS GÖNDERME VE ARAMA *****************************************
'Dim xcall As PhoneCalls
'Dim xsms As PhoneSms
'xsms.Send("+905335135121","2 sistemm çalıstı")
'StartActivity( xcall.Call("02127711379"))
'********************* SMS GÖNDERME VE ARAMA *****************************************
Dim c As Contact
Dim cs As Contacts2
'-------------Liste düzenleme-------------------
clv3.Initialize(Me, "clv3")
Activity.AddView(clv3.AsView, 0, 30%y, 100%x, 70%y)
Dim phonelist As List
phonelist.Initialize
'----------------------------------
Dim l As List
l = cs.GetAll(True,True)
Dim telf As Map
'Msgbox(l.Size, "kişi sayısı")
For i = 0 To l.Size - 1
c = l.Get(i)
telf= c.GetPhones
phonelist.Clear
For z=0 To telf.size-1
phonelist.Add(telf.GetKeyAt(z))
Next
clv3.Add(CreateListItem2( c.DisplayName, clv3.AsView.Width, 40dip,phonelist), 40dip, c.Id)
Log( c.DisplayName)
Next
ProgressDialogHide
' formatting using embedded tokens and the RichTextFormatter
Dim rs As RichString
Dim rsf As RichStringFormatter
rs.Initialize("{R}{T}{Blue}This2{Blue}{T}{R} {U}is{U} one more {Red}{BI}Rich{Red}String{BI}")
rsf.Initialize("{sample}")
rsf.AddToken("{R}", rsf.FORMAT_RELATIVESIZE, 1.5)
rsf.AddToken("{T}", rsf.FORMAT_TYPEFACE, "serif")
rsf.AddToken("{Blue}", rsf.FORMAT_COLOR, Colors.Blue)
rsf.AddToken("{Red}", rsf.FORMAT_COLOR, Colors.Red)
rsf.AddToken("{U}", rsf.FORMAT_UNDERSCORE, Null)
rsf.AddToken("{BI}", rsf.FORMAT_STYLE, rsf.STYLE_BOLD_ITALIC)
rs = rsf.Format(rs)
'Label3.Text = rs
End Sub
Sub spn2_ItemClick (Position As Int, Value As Object)
Msgbox("2 ci","")
End Sub
Sub spn_ItemClick (Position As Int, Value As Object)
Dim index As Int
index = clv3.GetItemFromView(Sender)
Dim pnl As Panel
pnl = clv3.GetPanel(index)
Dim spn,spn2 As Spinner
Dim lbl As Label
Dim chk As CheckBox
lbl = pnl.GetView(1)
spn = pnl.GetView(2)
chk = pnl.GetView(0)
spn2 = pnl.GetView(3)
lbl.Text = "telfon!"
Msgbox("Item value: " & clv3.GetValue(index) & CRLF & "spinner value: " & spn.GetItem(Position), "")
End Sub
Sub chk_CheckedChange(Checked As Boolean)
Dim index As Int
index = clv3.GetItemFromView(Sender)
Dim pnl As Panel
pnl = clv3.GetPanel(index)
Dim chk As CheckBox
chk = pnl.GetView(0)
'Msgbox("Item value: " & clv3.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
etiket_Click
End Sub
Sub etiket_Click
Dim index As Int
index = clv3.GetItemFromView(Sender)
Dim pnl As Panel
pnl = clv3.GetPanel(index)
Dim lbl As Label
Dim chk As CheckBox
lbl = pnl.GetView(1)
chk = pnl.GetView(0)
'Msgbox(lbl.Tag,"")
If chk.Checked=True Then
Dim st,bt As String
Dim rs As RichString
Dim rs2 As RichString
'Dim sf As StringFunctions
'Dim rsf As RichStringFormatter
rs2.Initialize(lbl.Text)
Dim ANS As List
Dim sf As StringFunctions
ANS = sf.Split(lbl.Text, " ")
If lbl.Tag=Null Then lbl.Tag=0
If lbl.Tag=ANS.Size Then lbl.Tag=0
If ANS.Size=1 Then
rs2.Color(Colors.Red,0,lbl.Text.Length)
Else
st=""
For i=0 To (lbl.Tag-1)
st=st&ANS.Get(i)&" "
Next
bt=st&ANS.get(lbl.Tag)
If lbl.Tag+0=0 Then
st=""
bt=ANS.get(lbl.Tag)
End If
rs2.Color(Colors.Red,st.Length,bt.Length)
lbl.Tag=(lbl.Tag*1)+1
End If
lbl.Text =rs2
st=st
Else
' temiz yazar
lbl.Text=lbl.Text
lbl.Tag=Null
End If
'rs.Initialize("{R}{T}{Blue}This2{Blue}{T}{R} {U}is{U} one more {Red}{BI}Rich{Red}String{BI}")
'rsf.Initialize("{sample}")
'rsf.AddToken("{R}", rsf.FORMAT_RELATIVESIZE, 1.5)
'rsf.AddToken("{T}", rsf.FORMAT_TYPEFACE, "serif")
'rsf.AddToken("{Blue}", rsf.FORMAT_COLOR, Colors.Blue)
'rsf.AddToken("{Red}", rsf.FORMAT_COLOR, Colors.Red)
'rsf.AddToken("{U}", rsf.FORMAT_UNDERSCORE, Null)
'rsf.AddToken("{BI}", rsf.FORMAT_STYLE, rsf.STYLE_BOLD_ITALIC)
'rs = rsf.Format(rs)
'lbl.Text =" tamam 2 dır"
End Sub
Sub Button_Click
Dim index As Int
index = clv3.GetItemFromView(Sender)
Dim pnl As Panel
pnl = clv3.GetPanel(index)
Dim lbl As Label
Dim chk As CheckBox
lbl = pnl.GetView(1)
chk = pnl.GetView(0)
lbl.Text = "Clicked!"
Msgbox("Item value: " & clv3.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
End Sub
Sub CheckBox1_CheckedChange(Checked As Boolean)
If Checked=True Then
Msgbox("chek edilidi","")
Else
Msgbox("iptal","")
End If
etiket_Click
End Sub
Sub Spinner1_ItemClick (Position As Int, Value As Object)
Msgbox( Spinner1.GetItem(Position),"")
End Sub
Sub Location_LocationChanged (Longitude As Double, Latitude As Double, Altitude As Double, Accuracy As Float, Bearing As Float, Provider As String, Speed As Float, Time As Long)
Log("demnene")
'ToastMessageShow("Long: " & Longitude & " - Lat: " & Latitude,True)
Log("Long: " & Longitude & " - Lat: " & Latitude)
'Msgbox("Long: " & Longitude & " - Lat: " & Latitude & "Accuracy = " & Accuracy & Chr(10) & "Bearing = " & Bearing &Chr(10) & "Provider="& Provider &Chr(10)&"Speed="& Speed&Chr(10) &"Time=" & Time, "")
End Sub
Sub Location_ProviderDisabled (Provider As String)
'ToastMessageShow("Location_ProviderDisable: " & Provider, True)
Log("Location_ProviderDisable: " & Provider)
End Sub
Sub Location_ProviderEnabled (Provider As String)
'ToastMessageShow("Location_ProviderEnabled: " & Provider, True)
Log("Location_ProviderEnabled: " & Provider)
End Sub
Sub Location_StatusChanged (Provider As String, Status As Int)
'ToastMessageShow("Location_StatusChanged: " & Provider & " Status: " & Status, True)
Log("Location_StatusChanged: " & Provider & " Status: " & Status)
End Sub
costum listwiew
B4X:
'version: 1.10
#Event: ItemClick (Index As Int, Value As Object)
Sub Class_Globals
Private sv As ScrollView
Private items As List
Private panels As List
Private dividerHeight As Float
Private pressedDrawable As Object
Private EventName As String
Private CallBack As Object
Private su As StringUtils
Public DefaultTextSize As Int
Public DefaultTextColor As Int
Public DefaultTextBackgroundColor As Int
Private DefaultTextBackground As Object
End Sub
Public Sub Initialize (vCallback As Object, vEventName As String)
sv.Initialize2(0, "sv")
items.Initialize
panels.Initialize
dividerHeight = 2dip
EventName = vEventName
CallBack = vCallback
sv.Color = 0xFFD9D7DE 'this sets the dividers color
Dim r As Reflector
Dim idPressed As Int
idPressed = r.GetStaticField("android.R$drawable", "list_selector_background")
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
pressedDrawable = r.RunMethod2("getDrawable", idPressed, "java.lang.int")
DefaultTextColor = Colors.White
DefaultTextSize = 16
DefaultTextBackgroundColor = Colors.Black
DefaultTextBackground = Null
End Sub
'Returns a view object that holds the list.
Public Sub AsView As View
Return sv
End Sub
Public Sub DesignerCreateView(base As Panel, lbl As Label, props As Map)
Dim parent As Panel
Dim r As Reflector
r.Target = base
parent = r.RunMethod("getParent")
base.RemoveView 'remove the base panel
parent.AddView(sv, base.Left, base.Top, base.Width, base.Height)
DefaultTextSize = lbl.TextSize
DefaultTextColor = lbl.TextColor
DefaultTextBackground = base.Background
End Sub
'Clears all items.
Public Sub Clear
items.Clear
panels.Clear
sv.Panel.Height = 0
For i = sv.Panel.NumberOfViews - 1 To 0 Step -1
sv.Panel.RemoveViewAt(i)
Next
End Sub
'Returns the number of items.
Public Sub GetSize As Int
Return items.Size
End Sub
'Returns the Panel stored at the specified index.
Public Sub GetPanel(Index As Int) As Panel
Dim p As Panel
p = panels.Get(Index) 'this is the parent panel
Return p.GetView(0)
End Sub
'Returns the value stored at the specified index.
Public Sub GetValue(Index As Int) As Object
Return items.Get(Index)
End Sub
'Removes the item at the specified index.
Public Sub RemoveAt(Index As Int)
Dim removePanel, p As Panel
removePanel = panels.Get(Index)
For i = Index + 1 To items.Size - 1
p = panels.Get(i)
p.Tag = i - 1
p.Top = p.Top - removePanel.Height - dividerHeight
Next
sv.Panel.Height = sv.Panel.Height - removePanel.Height - dividerHeight
items.RemoveAt(Index)
panels.RemoveAt(Index)
removePanel.RemoveView
End Sub
'Adds a text item. The item height will be adjusted based on the text.
Public Sub AddTextItem(Text As String, Value As Object)
InsertAtTextItem(items.Size, Text, Value)
End Sub
'Inserts a text item at the specified index.
Public Sub InsertAtTextItem(Index As Int, Text As String, Value As Object)
Dim pnl As Panel
pnl.Initialize("")
Dim lbl As Label
lbl.Initialize("")
lbl.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
pnl.AddView(lbl, 5dip, 2dip, sv.Width - 5dip, 20dip)
lbl.Text = Text
lbl.TextSize = DefaultTextSize
lbl.TextColor = DefaultTextColor
If DefaultTextBackground <> Null Then
pnl.Background = DefaultTextBackground
Else
pnl.Color = DefaultTextBackgroundColor
End If
Dim minHeight As Int
minHeight = su.MeasureMultilineTextHeight(lbl, Text)
lbl.Height = Max(50dip, minHeight)
InsertAt(Index, pnl, lbl.Height + 2dip, Value)
End Sub
'Adds a custom item at the specified index.
Public Sub InsertAt(Index As Int, Pnl As Panel, ItemHeight As Int, Value As Object)
Dim sd As StateListDrawable
sd.Initialize
sd.AddState(sd.State_Pressed, pressedDrawable)
sd.AddCatchAllState(Pnl.Background)
'create another panel to handle the click event
Dim p As Panel
p.Initialize("panel")
p.Background = sd
Dim cd As ColorDrawable
cd.Initialize(Colors.Transparent, 0)
Pnl.Background = cd
p.AddView(Pnl, 0, 0, sv.Width, ItemHeight)
p.Tag = Index
If Index = items.Size Then
items.Add(Value)
panels.Add(p)
Dim top As Int
If Index = 0 Then top = dividerHeight Else top = sv.Panel.Height
sv.Panel.AddView(p, 0, top, sv.Width, ItemHeight)
Else
Dim top As Int
If Index = 0 Then
top = dividerHeight
Else
Dim previousPanel As Panel
previousPanel = panels.Get(Index - 1)
top = previousPanel.top + previousPanel.Height + dividerHeight
End If
Dim p2 As Panel
For i = Index To panels.Size - 1
p2 = panels.Get(i)
p2.top = p2.top + ItemHeight + dividerHeight
p2.Tag = i + 1
Next
items.InsertAt(Index, Value)
panels.InsertAt(Index, p)
sv.Panel.AddView(p, 0, top, sv.Width, ItemHeight)
End If
sv.Panel.Height = sv.Panel.Height + ItemHeight + dividerHeight
If items.Size = 1 Then sv.Panel.Height = sv.Panel.Height + dividerHeight
End Sub
'Adds a custom item.
Public Sub Add(Pnl As Panel, ItemHeight As Int, Value As Object)
InsertAt(items.Size, Pnl, ItemHeight, Value)
End Sub
'Scrolls the list to the specified item.
Public Sub JumpToItem(Index As Int)
Dim top As Int
Dim p As Panel
For i = 0 To Min(Index - 1, items.Size - 1)
p = panels.Get(i)
top = top + p.Height + dividerHeight
Next
sv.ScrollPosition = top
'The scroll position doesn't always gets updated without two calls to DoEvents
DoEvents
sv.ScrollPosition = top
DoEvents
End Sub
Private Sub Panel_Click
If SubExists(CallBack, EventName & "_ItemClick") Then
Dim v As View
v = Sender
CallSub3(CallBack, EventName & "_ItemClick", v.Tag, items.Get(v.Tag))
End If
End Sub
'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
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
B4X:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
demnene
Long: 28.6404656 - Lat: 41.0905137
phone name1
phone name12
phone name13
phone name14
phone name51
phone name16
phone name17
Long: 28.6404656 - Lat: 41.0905139
demnene
Long: 28.6404657 - Lat: 41.0905139
Error occurred on line: 212 (control_view)
java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.Arrays$ArrayList.get(Arrays.java:66)
at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
at b4a.example.main._etiket_click(main.java:749)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4232)
at android.view.View$PerformClick.run(View.java:17298)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)