Android Question Newbie: how to set ImageView to a specific picture?

morosh

Member
Hello:
Newbie with ImageView, I like to set interactivly an ImageView to a specific picture following a specific event, let's say now a button click: I have two pictures pic1.jpg and pic2.jpg
and I like to set ImageView1 to pic1.jpg following a Button1 click, and to pic2.jpg following a Button2 click, How to?
I've done some search unsuccessfully.
setting ImageView:
#Region  Project Attributes
    #ApplicationLabel: bluetooth1
    #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
    Dim Serial1 As Serial
    Dim TextReader1 As TextReader
    Dim TextWriter1 As TextWriter
    Dim Timer1 As Timer
    Dim connected As Boolean
End Sub

Sub Globals
    Dim b As Beeper
    Dim But1 As Button
    Dim But2 As Button
    Dim But3 As Button
    Dim But4 As Button
    Private ImageView1 As ImageView
    Private ImageView2 As ImageView
End Sub


Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        Serial1.Initialize("Serial1")
        Timer1.Initialize("Timer1", 200)
    End If
    Activity.LoadLayout("layout1")
    Activity.AddMenuItem("Connect", "mnuConnect")
    Activity.AddMenuItem("Disconnect", "mnuDisconnect")
    EditText1.Color = Colors.ARGB(255,51,153,0)
    'EditText1.Color = Colors.Green
    b.Initialize(100, 200)
End Sub

Sub Activity_Resume
    If Serial1.IsEnabled = False Then
        Msgbox("Please enable Bluetooth.", "")
    Else
        Serial1.Listen 'listen for incoming connections
    End If
End Sub

Sub mnuConnect_Click
    Dim PairedDevs As Map
    PairedDevs = Serial1.GetPairedDevices
    Dim l As List
    l.Initialize
    For i = 0 To PairedDevs.Size - 1
        l.Add(PairedDevs.GetKeyAt(i))
    Next
    Dim res As Int
    res = InputList(l, "Choose Dev", -1) 'show list with paired Devs
    If res <> DialogResponse.CANCEL Then
        Serial1.Connect(PairedDevs.Get(l.Get(res))) 'convert the name to mac address
    End If
End Sub

Sub Serial1_Connected (Success As Boolean)
    If Success Then
        ToastMessageShow("Connected successfully", False)
        TextReader1.Initialize(Serial1.InputStream)
        TextWriter1.Initialize(Serial1.OutputStream)
        Timer1.Enabled = True
        connected = True
    Else
        connected = False
        Timer1.Enabled = False
        Msgbox(LastException.Message, "Error connecting.")
    End If
End Sub

Sub mnuDisconnect_Click
    Serial1.Disconnect
    connected = False
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub But1_Click


End Sub

Sub But2_Click

End Sub
 

drgottjr

Expert
Licensed User
Longtime User
there is something a little strange about your request:
and I like to set ImageView1 to pic1.jpg following a Button1 click, and to pic2.jpg following a Button2 click, How to?
but to answer it directly:
B4X:
sub globals
  dim bitmap1, bitmap2 as bitmap

sub create
bitmap1 = loadbitmap(file.dirassets, "pic1.jpg")
bitmap2 = loadbitmap(file.dirassets,"pic2.jpg")


but1_click
   imageview1.bitmap = bitmap1

but2_click
   imageview2.bitmap = bitmap2

there are a number of ways to accomplish the same thing.
 
Upvote 0
Top