[Android n00b] Please help, Coding problem

Put your problem here if it does not fit any of the other categories.

[Android n00b] Please help, Coding problem

Postby JonnySnip3r » Wed Apr 08, 2009 1:29 pm

Hey guys dorry if this is in the wrong section.

i have just followed a tutorial from google which was this one: http://developer.android.com/guide/tuto ... inner.html

I have made this app and it runs fine but can somebody tell me how i would add say some information if a user clicks a planet then i could maybe give them some information.

i am a n00b lol and hopefully i can learn alot from this forum.

Thanks :)
JonnySnip3r
Developer
Developer
 
Posts: 30
Joined: Wed Apr 08, 2009 1:23 pm

Top

Postby killa.fr0gg » Wed Apr 22, 2009 11:01 pm

What exactly are you trying to accomplish? If you just want to give the user information upon the click of an item, just set onClickListener() to the planets and create an alert dialog. If you need help with the code, post the details of what you need and I'll see if I can't help you out.
killa.fr0gg
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Apr 21, 2009 9:35 am
Location: Los Angeles

Postby JonnySnip3r » Fri Apr 24, 2009 3:22 am

Hey man, yeah when the user clicks a planet then a dialog will be displayed maybe with an image is that possible? and id there anychance you could give a few pointers on that - n00b :( lol thanks man :)
JonnySnip3r
Developer
Developer
 
Posts: 30
Joined: Wed Apr 08, 2009 1:23 pm

Postby jjttjj » Fri Apr 24, 2009 9:04 pm

Hey man I'm also pretty new at this and just figured out how to do what you're trying to do the other day. You're going to want something like this:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3. public void onCreate(Bundle savedInstanceState) {
  4.  
  5.     super.onCreate(savedInstanceState);
  6.  
  7.     setContentView(R.layout.main);
  8.  
  9.  
  10.  
  11.     Spinner s = (Spinner) findViewById(R.id.spinner);
  12.  
  13.     ArrayAdapter adapter = ArrayAdapter.createFromResource(
  14.  
  15.             this, R.array.planets, android.R.layout.simple_spinner_item);
  16.  
  17.     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  18.  
  19.     s.setAdapter(adapter);
  20.  
  21.  
  22.  
  23. //new stuff:
  24.  
  25.  
  26.  
  27.     s.setOnItemSelectedListener(
  28.  
  29.                new OnItemSelectedListener() {
  30.  
  31.                           public void onItemSelected(
  32.  
  33.                                 AdapterView parent, View view, int position, long id) {
  34.  
  35.  
  36.  
  37.           //put stuff to do on when something is selected from the spinner here.
  38.  
  39.            //this is an example of how to refer to the selected item:
  40.  
  41.                                         String selectedItemString = parent.getSelectedItem();
  42.  
  43.                                         }
  44.  
  45.  
  46.  
  47.                                         public void onNothingSelected(AdapterView parent) {
  48.  
  49.                                                 setDefaultKeyMode(DEFAULT_KEYS_DISABLE);
  50.  
  51.                                         }
  52.  
  53.                                 });
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


As far as I understand, what this does is create an anonymous method, which can only be seen and used when the spinner is clicked, to handle the click. (Sorry for the sloppy indentations and such)
jjttjj
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Apr 23, 2009 8:32 pm

Postby JonnySnip3r » Sat Apr 25, 2009 10:51 pm

Thanks dude for your help will give this a try :)
JonnySnip3r
Developer
Developer
 
Posts: 30
Joined: Wed Apr 08, 2009 1:23 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 24 guests