• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tring to do a spinner and i am getting errors

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to do a spinner but i keep getting errors in my code. I followed the tutorials and tried to fit it to my needs but it doesn't seem to be working. I think the problems lies in the fact i'm not sure how to code these views if they are not in an activity all by themselves. Most tutorials have them in a single activity. But i am coding for a tablet and the exist within a fragment. Those are just my thoughts and here is the errors:

The method onCreate(Bundle) of type PatientFormFragment.NewPatientTask.GenderSpinner must override a superclass method from the "public void onCreate(Bundle savedInstanceState)"


The method onCreate(Bundle) is undefined for the type View for super.onCeate(savedInstanceState)



thats just the code for the spinner...if you need i can post the code for the whole fragment...but it is very long. I ask that you please be patient with me. I'm new and been working on these problems for over 2 months and have been kicked off other various help sites because my questions weren't good enough. But i find it hard to form correct questions when i'm not sure what the real problems are.
thanks
jj
 
Saloon Keeper
Posts: 7602
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
onCreate is a method in Activity, not in View. In a View, you can get the Activity by casting the Context object that gets passed into the constructor.
 
jawann jefferson
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this what you mean by casting Context with Activity:


i am still getting the same error... eclipse is asking me to remove the "@Override"
 
Tim Moores
Saloon Keeper
Posts: 7602
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again: onCreate is a method of Activity, not View. It has no place in this class.

If you want to use the Activity object, the code would look something like this:



It sounds a bit as if you do not fully understand how Views interact with the main Activity (or other Activities, there can be several in an app).
 
jawann jefferson
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My next question is do i need to use onCreate since its already used in the fragment? and just write code on how the spinner is supposed to work?
 
Tim Moores
Saloon Keeper
Posts: 7602
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Every subclass of Activity has an onCreate method, but not subclasses of View.
 
jawann jefferson
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok here's my new code. I deleted all that onCreate stuff cause i didn't need it but now i'm getting a new error


for GenderSpinner(this); i'm getting "Syntax error on token "this", ( expected after this token". Not sure why. I tried R.layout.patientformfragment (name of fragment it is in) and got the same error. I also tried admissionshome (name of activity it is in) and still got the same error
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic