Android Question spinner added with code

tufanv

Expert
Licensed User
Longtime User
Hello

I created a spinner in my code ( not in designer)
but the initialize method line gives me an error:

B4X:
java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead

I didnt set any click listener for this view. Why am i getting it ? I searched the forum for the error msg, some people say stg about openspinner but i couldnt understand what it is .

ty
 

tufanv

Expert
Licensed User
Longtime User
You should show your code.

declared the spinner in globals:
B4X:
Dim labelinstructionsec(10) As Spinner

under jobdone :

B4X:
                        labelinstructionsec(i).Initialize("labelinstructionsec")
                        labelinstructionsec(i).TextColor=Colors.RGB(255,170,7)
                        labelinstructionsec(i).textsize=14

added the spinner to panel

B4X:
panel(i).AddView(labelinstructionsec(i),scrolltraining2.Width/2-135dip,75,270,30)

and this is the itemclick sub :

B4X:
Sub labelinstructionsec_ItemClick (Position As Int, Value As Object)
        Dim lbl As Spinner = Sender
    isayisi=lbl.tag

    labelinstructionsec(isayisi).clear
    labelinstructionsec(isayisi).Add("Run On Back")
    labelinstructionsec(isayisi).Add("Run In Pack")
    labelinstructionsec(isayisi).Add("Run In Front of Pack")
    labelinstructionsec(isayisi).Add("Run On Lead")
    labelinstructionsec(isayisi).SelectedIndex=0   

End Sub

error occurs on jobdone's spinner initalize line.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I don't know why you get this error.
I would try to put the Initialize out of the JobDone routine, and perhpas change the the event name.
Not sure if this will solve the problem.

Two comments:
- In this line you should use dip values not pure pixel values.
panel(i).AddView(labelinstructionsec(i),scrolltraining2.Width/2-135dip,75,270,30)
- I don't see where you add the labelinstructionsec(i).Tag property.
 
Last edited:
Upvote 0

tufanv

Expert
Licensed User
Longtime User
I don't know why you get this error.
I would try to put the Initialize out of the JobDone routine, and perhpas change the the event name.
Not sure if this will solve the problem.

Two comments:
- In this line you should use dio values not pure pixel values.
panel(i).AddView(labelinstructionsec(i),scrolltraining2.Width/2-135dip,75,270,30)
- I don't see where you add the labelinstructionsec(i).Tag property.
How can i get the initalize out of jobdone ? the spinners are initialized according to data received in jobdone so i think it is not possible to move it. I also changed the event name but no luck..

Yeah i will change them to dip , it is a project from b4i so it takes some time to change all those =)
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Where do you initialize the panel ?
I think you could initialize the Spinners where you initialize the panels and add them to the panels there..
I also initialize the panel in jobdone because number of panels are changing according to parser's size: dim l as list = parser.nextarray

lets say i got 6 records from the json. I add 6 panels.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
This means that you are calling Jobdone only once, otherwise you will add new instances of the panels.
I don't understand why you get this error. I made a very small test program, without http, and get no error.
 

Attachments

  • TestSpinners.zip
    6.8 KB · Views: 207
Upvote 0

tufanv

Expert
Licensed User
Longtime User
This means that you are calling Jobdone only once, otherwise you will add new instances of the panels.
I don't understand why you get this error. I made a very small test program, without http, and get no error.

I use scroll and with every jobdone i clear everything on the scroll so when i call it multiple times no problem occurs. Anyways thanks for your help , i also dont know why i am getting it . I will report back if i can fix that.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
This means that you are calling Jobdone only once, otherwise you will add new instances of the panels.
I don't understand why you get this error. I made a very small test program, without http, and get no error.
you were right. I had changed the event name , but there were 2 spinners i only changed one of them. Later i realized there are 2 so when i change the eventname of both spinenrs the problem fixed. Thanks so much !
 
Upvote 0
Top