tamim abweini tamim abweini - 1 year ago 104
Vb.net Question

android studio image button change src when clicked

I'm trying to make an android app and need some help, i want to make imagebutton1 that have a src1 already to change its src1 and a textbox1 text "a" when clicked to src2 and the textbox1 text become "b" if clicked again change to src1 and the text to "a" etc...
i used to do this in vb.net by

Private Sub units_Click(sender As Object, e As EventArgs) Handles units.Click

counter = counter + 1
If (-1) ^ counter < 0 Then
units.Image = WindowsApplication1.My.Resources.Resources.lup
Label3.Text = "a"

units.Image = WindowsApplication1.My.Resources.Resources.ldown
Label3.Text = "b"

End If
End Sub

please help and mention what each line do because I'm new to java

Answer Source

I think you need to take a look into a Java book, there are a lot of them, Thinking in Java for example. And read the Android documentation, there is a lot of information there This question it's very basic after you read a little bit.

textView.setOnClickListener(new View.OnClickListener() {
                public int counter;

                public void onClick(View v) {
                    counter += 1;
                    if (counter % 2 == 0) {
                        textView.setText("Text 1");
                    } else {
                        textView.setText("Text 2");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download