Android Question (solved) Use swipe instead of btn_click

anOparator

Active Member
Licensed User
Longtime User
Ok, I have an imgVw1 and a lbl1 in a Panel,
outside of the Panel are btnNext and btnPrevious that pull imgVw1.bmp# and lbl1.txt# from sample.db, this works like a charm.
Attempts to replace btnNext and btnPrevious with the "GestureDetector" or "Gestures" lib deliver no Log entries, or encouraging results.

With 200+ image/text changes what would be a recommended approach to update imgVw1/lbl1 using a horizontal swipe instead of buttons.
Thanks in advance for all links and pointers.
 

Brandsum

Well-Known Member
Licensed User
Attempts to replace btnNext and btnPrevious with the "GestureDetector" or "Gestures" lib deliver no Log entries, or encouraging results.
As per my understanding, gesture detector is not working for you. Post the relevant code so that someone can help you to fix it.
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
GestureDetector_SwipeLV works perfectly as is,
B4X:
 Sub Globals
   Dim GD As GestureDetector
   Dim LV As ListView               ' am stepping thru a db, not a ListView
   Dim FilterMoveEvents As Boolean
   Dim DiscardOtherGestures As Boolean
End Sub

B4X:
 Sub Activity_Create(FirstTime As Boolean)

   'Binds a GD to this ListView
   GD.SetOnGestureListener(LV, "Gesture")   ' what to Bind GD to in order to replace btn_Next ? ? ?


Currently btnNext keeps track of db RowIDs with
B4X:
 Sub btnNext_Click
If DateTime.Now - Starter.LastActionTime < 300 Then Return   ' Prevent rapid btn clicks
   Starter.LastActionTime = DateTime.Now
   Starter.pos = Starter.pos + 1
   Starter.posPrev = Starter.pos - 1
   If Starter.pos < (Starter.lstRowIDs.Size - 1) Then
       Starter.posNext = Starter.pos + 1
   Else If Starter.pos = (Starter.lstRowIDs.Size - 1) Then
       Starter.posNext = 0
   Else
       Starter.pos = 0
       Starter.posNext = Starter.pos + 1
   End If
   updateNext
End Sub
and puts the next db img and txt fields into imgVw1.bmp and lbl1.txt using
B4X:
 Sub updateNext
   Dim Cursor1 As Cursor = Starter.SQL1.ExecQuery("SELECT image FROM table1 WHERE rowID = " & Starter.lstRowIDs.Get(Starter.posNext))
   Dim binimageR() As Byte, OtptR As InputStream
   Cursor1.Position = 0
   binimageR = Cursor1.GetBlob("image")
   OtptR.InitializeFromBytesArray(binimageR, 0, binimageR.Length)
   BmpR.Initialize2(OtptR)
   OtptR.Close
   Dim outR As OutputStream = File.OpenOutput(File.DirInternal, "Picturer.jpg" , False)
   BmpR.WriteToStream(outR, 100, "JPEG") ' write the bitmap to the stream
   outR.Close
   Cursor1.Close
   btnN.Bitmap = ri.CreateBitmap(LoadBitmap(File.DirInternal,"Picturer.jpg"))   
End Sub
The goal, to have GestureDetector "Left/Right" query a db the same way btnNext does.
Thanks.
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
Thanks, it was that easy.
Since imgVw1 and lbl1 alternate visibility I attached GD to both views, and it adds a smoother feel to the functions/events that the buttons handled.
 
Upvote 0
Top