Android Question Set seekbar value with edittext

patrickfailing

New Member
Licensed User
Longtime User
I am trying to set the value of an existing seekbar with edittext. I need to be able to increase the value in increments of 1.



B4X:
'Events declaration

#Event: ValueChanged(Value As Int, UserChanged As Boolean)


'Class module

Private Sub Class_Globals

Privatedr1,dr2,dr3AsGradientDrawable

Privateslider, caretAsImageView

PrivateVpos, H, W, MaxV, DAsInt

PrivateVmoduleAsObject

PrivateVbase, coverAsPanel

PrivateBarNameAsString

End Sub


'Initializes the object. No need to use if the object is defined by the designer.

'Module is the launching module.

Public Sub Initialize(Module AsObject, Eventname AsString)

Vmodule = Module

BarName = Eventname

End Sub


'If you create the object by code, not by the designer, use this sub after initialization.

Public Sub CodeCreateView( width AsInt ,height AsInt, MaxValue AsInt)

H = height

W = width

MaxV = MaxValue

D = 20dip' default caret height

Vbase.Initialize("")

ContinueCreation

End Sub



Private Sub DesignerCreateView(base AsPanel, Lbl AsLabel, Props AsMap)'ignore

base.Left = Lbl.Left

base.Top = Lbl.top

base.Width = Lbl.Width

base.Height = Lbl.Height

Vbase.Initialize("")

base.AddView(Vbase,0, 0, Lbl.Width, Lbl.Height)

H = Lbl.Height

W = Lbl.Width

MaxV = Lbl.text

ContinueCreation

End Sub


Private Sub ContinueCreation

D = 20dip' default caret height

slider.Initialize("")

Vbase.AddView(slider,0,0,W,H)

caret.Initialize("")

Vbase.AddView(caret,0,H/2-D/2,W,D)

cover.Initialize("cover")

Vbase.AddView(cover,0,0,W,H)

' These are the default colors

setColors(Colors.Black,Colors.white, Colors.red, Colors.white)

End Sub


'Sets the colors of the bar

Sub setColors(BackGround AsInt,basecolor AsInt,slidercolor AsInt, caretcolor AsInt)

Dim clr(3) AsInt

clr = Array AsInt(BackGround,basecolor,BackGround)

dr1.Initialize("LEFT_RIGHT",clr)

Vbase.BackGround = dr1

clr = Array AsInt(BackGround,slidercolor,BackGround)

dr2.Initialize("LEFT_RIGHT",clr)

slider.BackGround = dr2

clr = Array AsInt(BackGround,caretcolor,BackGround)

dr3.Initialize("TOP_BOTTOM",clr)

caret.BackGround = dr3

End Sub


Sub AsView AsView'ignore

ReturnVbase

End Sub


' Sets the Max value of the bar

Sub setMaxValue(Value AsInt)

MaxV = Value

End Sub



'Sets the height of the caret.

'The default is 20dip.

Sub setCaretHeight(value AsInt)

D = value

caret.Height = D

caret.top = Max(Min(slider.top-D/2, H-D), 0)

End Sub


Private Sub setPosition(Value AsInt, userchanged AsBoolean)

slider.height = Max(Min(H * Value / MaxV, H ),0)

slider.Top = H - slider.height

caret.top = Max(Min(slider.top-D/2, H-D), 0)

Vbase.Invalidate

IfSubExists(Vmodule, BarName & "_ValueChanged") Then

CallSub3(Vmodule,BarName & "_ValueChanged", Value , userchanged )

EndIf

End Sub


' Sets the value of the bar

' ValueChanged event will be raised with Userchanged = false

'This function must be performed by code at least once prior to use of the bar.

Sub setValue(Value AsInt)

Vpos = Value

H = Vbase.Height

setPosition(Vpos,False)

End Sub


' Returns the current value of the bar

Sub getValue AsInt

ReturnVpos

End Sub



Private Sub cover_Touch(Action AsInt, X AsFloat, Y AsFloat) AsBoolean

Dim k AsInt

k = (1-Y/Vbase.Height)* MaxV

k = Max(Min(k, MaxV),0)

setPosition(k, True)

ReturnTrue

End Sub
I am trying to set the value of an existing seekbar with edittext. I need to be able to increase the value in increments of 1.
 
Last edited:

NJDude

Expert
Licensed User
Longtime User
You have to enclose your code like this:

[code]
Dim Name As String
[/code]

That will show like:
B4X:
Dim Name As String
But when you have a large code, better to attach it, on the IDE, click on FILE -> EXPORT AS ZIP.

Welcome to the B4A forums by the way.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…