#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Private chooser As ContentChooser
Type ItemValue2 (Lanel2 As Label, ImageView2 As ImageView)
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.
Private CLV1 As CustomListView
Private Label2 As Label
Private ImageView2 As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
Dim iv2 As ItemValue2
iv2.Initialize
CLV1.Add(CreateItem2(iv2,$"Фото 1:"$),iv2)
CLV1.Add(CreateItem2(iv2,$"Фото 2:"$),iv2)
End Sub
Private Sub CreateItem2 (iv2 As ItemValue2, ti2 As String) As B4XView
Dim p2 As B4XView=xui.CreatePanel("")
p2.SetLayoutAnimated(0,0,0,100%x,180dip)
p2.LoadLayout("Item2")
iv2.Lanel2=Label2
iv2.Lanel2.Text=ti2
iv2.ImageView2=ImageView2
Return p2
End Sub
Sub Button2_Click
Dim index As Int= CLV1.GetItemFromView(Sender)
Log ($"Button #${index}"$)
chooser.Initialize("chooser")
chooser.Show("image/*", "Choose image")
End Sub
Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
If Success Then
'Dim bmp As Bitmap
'bmp.Initialize(Dir, FileName)
'Activity.SetBackgroundImage(bmp)
Dim index As Int= CLV1.GetItemFromView(Sender)
Dim iv2 As ItemValue2 = CLV1.GetValue(index)
iv2.ImageView2=ImageView2
ImageView2.Bitmap = LoadBitmap(Dir, FileName)
Else
ToastMessageShow("Фото не выбрано...", True)
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
This is an app description, not a question.Pushing the button I want a chosen photo be added to according ImageView. Then I choose another photo and it is added nearby and etc. If you push a photo, it is deleted.
Logger connected to: 12184415843991
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Class not found: b4a.example.customlistview, trying: b4a.example.test25.customlistview
** Activity (main) Resume **
Button #0
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
customlistview_getitemfromview (java line: 413)
java.lang.ClassCastException: anywheresoftware.b4a.phone.Phone$ContentChooser cannot be cast to android.view.View
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:53)
at anywheresoftware.b4a.objects.B4XViewWrapper.getParent(B4XViewWrapper.java:122)
at b4a.example.test25.customlistview._getitemfromview(customlistview.java:413)
at b4a.example.test25.main._chooser_result(main.java:400)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.phone.Phone$ContentChooser$1.ResultArrived(Phone.java:843)
at anywheresoftware.b4a.BA$4.run(BA.java:566)
at anywheresoftware.b4a.BA.setActivityPaused(BA.java:432)
at b4a.example.test25.main$ResumeMessage.run(main.java:305)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5281)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:932)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:748)
at dalvik.system.NativeStart.main(Native Method)
Please could you give any example?You can use xCustomListView with a horizontal orientation for this layout.
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("ImagenFoto")
swith.Initialize("")
barrFoto.AddView(swith,20%x,10%x,Gravity.RIGHT)
ProgressDialogShow2("Cargando las fotos...",False)
FotoFileDir = rp.GetSafeDirDefaultExternal("Folder") & "/Fotos/"
LoadImagen
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Activity.Finish
End Sub
Sub CLV1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
Dim ExtraSize As Int = 20
For i = 0 To CLV1.Size - 1
Dim p As B4XView = CLV1.GetPanel(i)
If i > FirstIndex - ExtraSize And i < LastIndex + ExtraSize Then
'visible+
If p.NumberOfViews = 0 Then
Dim fl As FotosL = CLV1.GetValue(i)
p.LoadLayout("pnlImagen")
lblTitle.Text = fl.Nombre
ImageView1.SetBitmap(xui.LoadBitmapResize(FotoFileDir, fl.ImagenArchivo, 100%x, 100%y, True))
End If
Else
'Not visible
If p.NumberOfViews > 0 Then
p.RemoveAllViews '<--- remove the layout
End If
End If
Sleep(0)
Next
ProgressDialogHide
End Sub
Sub LoadImagen
Try
Dim files As List
files.Initialize
files = File.ListFiles(FotoFileDir)
If files.Size = 0 Then
ToastMessageShow("No se ha encontrado imagenes " & CRLF & FotoFileDir, True)
ProgressDialogHide
Else
For i = 0 To files.Size - 1
Dim FL As FotosL
FL.Initialize
FL.Nombre = files.Get(i)
FL.ImagenArchivo = files.Get(i)
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, 100%y)
CLV1.Add(p,FL)
Next
End If
Catch
Log(LastException)
End Try
End Sub
I do not understand, can you give an example?Using content chooser to hold the image path then load it to imageview in the xclv but you do this one by one
Dim Chooser As ContentChooser
Chooser.Initialize("chooser")
'and you can use this chooser in any click event
Chooser.Show("image/*", "Choose image")
'now grab the file path
Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
If Success Then
'if choosen use loadbitmap to load image from path
'LoadBitmap(Dir,FileName)// file path
' you can pass a sub to load that file to xcustomlist view here
end if
End sub
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#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 Chooser As ContentChooser
Private MyCLV As CustomListView
Private Button1 As Button
Private CLV_IV As CustomListView
Private ImageView1 As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Main")
Chooser.Initialize("chooser")
For i = 1 To 20
MyCLV.Add(CreateListItem("MyText"&i),i)
Next
End Sub
Sub CreateListItem(Text As String) As Panel
Dim p As Panel
p.Initialize("")
p.SetLayout(0, 0, 100%x, 150dip)
p.LoadLayout("Item")
Button1.Text = Text
Return p
End Sub
Sub CreateListItem2(btm As Bitmap) As Panel
Dim p As Panel
p.Initialize("")
p.SetLayout(0, 0, 100dip, 100dip)
p.LoadLayout("Item_IV")
ImageView1.Bitmap=btm
Return p
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
Dim index As Int = MyCLV.GetItemFromView(Sender)
Dim pnl As B4XView = MyCLV.GetPanel(index)
Dim clv As B4XView= pnl.GetView(1)
Chooser.Show("image/*", "Choose image")
Log("Checked items: " & index)
'Dim lbl As B4XView = pnl.GetView(0)
'Dim chk As B4XView = pnl.GetView(2)
End Sub
Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
If Success Then
'if choosen use loadbitmap to load image from path
CLV_IV.Add(CreateListItem2(LoadBitmapResize(Dir,FileName,100dip,100dip,True)),0)
'LoadBitmap(Dir,FileName)
' you can pass a sub to load that file to xcustomlist view here
End If
End Sub
CLV_IV.Add(CreateListItem2(LoadBitmapResize(Dir,FileName,100%x,100%y,True)),0)
Look at this example, whatever you ask me ...
Looked, but did not understand how you can use for my program ...Anyway, have you tried the example I sent you?