Android Question Download and view a picture from the web

Ionut Indigo

Member
Licensed User
Longtime User
Thank you Erel, but i might be doing something wrong, because i got this error.

B4X:
main_clv_itemclick (java line: 308)
java.lang.ClassCastException: b4a.maps.example.customlistview
    at b4a.maps.example.main._clv_itemclick(main.java:308)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:858)
    at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:823)
    at b4a.maps.example.customlistview._panel_click(customlistview.java:365)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
    at android.view.View.performClick(View.java:2485)
    at android.view.View$PerformClick.run(View.java:9080)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3683)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.ClassCastException: b4a.maps.example.customlistview

Here is the rest of the example :
B4X:
Sub Globals
   Dim clv As CustomListView
   Dim Label1 As Label
   Dim ImageView1 As ImageView
   Dim ImageViews As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     CallSubDelayed(DownloadListService, "StartDownload")
   End If
   ImageViews.Initialize
   clv.Initialize(Me, "clv")
   Activity.AddView(clv.AsView, 0, 0, 100%x, 100%y)
End Sub

Sub Activity_Resume
   CallSubDelayed(DownloadListService, "AfterActivityResume")
End Sub

Sub ShowImage(Image As Bitmap, Index As Int)
   If ImageViews.Size > Index Then
     Dim iv As ImageView = ImageViews.Get(Index)
     iv.SetBackgroundImage(Image)
   End If
End Sub

Sub CreateItems(links As List)
   If clv.GetSize > 0 Then Return
   For Each link As String In links
     Dim p As Panel
     p.Initialize("")
     clv.Add(p, 50dip, link)
     p.LoadLayout("ListItem")
     Label1.Text = link
     ImageViews.Add(ImageView1)
   Next
End Sub

Sub clv_ItemClick (Index As Int, Value As Object)
   Activity.Title = Value
   Dim IV As ImageView = Sender
   Activity.SetBackgroundImage(IV.Bitmap)
End Sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
try this ...
B4X:
Sub clv_ItemClick (Index As Int, Value As Object)
 
   Dim pnl As Panel
   pnl = clv.GetPanel(Index)
 
   Dim imv As ImageView
   imv =  pnl.GetView(0)  '@  GetView(?) the index of views in the clv line panel. Is ImageView the first loaded view ?
   Activity.SetBackgroundImage(imv.Bitmap)
   End If

End Sub
 
Last edited:
Upvote 0

Ionut Indigo

Member
Licensed User
Longtime User
Thank you Erel, I've solved the "problem" and uploaded the project if someone else needs it.
 

Attachments

  • DownloadImage&Display.zip
    14.8 KB · Views: 172
  • di&d.jpg
    di&d.jpg
    84.1 KB · Views: 137
Upvote 0
Top