I need help with getting employee records to display within a Spinner
after first selecting a department within a ListView. I'm trying to
get the Spinner object within the 'onItemClick' listener method of the
ListView but it's coming back null. The Spinner is in its own layout
file, as is the ListView. Below is part of the code from the
'onCreate' method of my Activity subclass:


                ListView lv =(ListView)findViewById(R.id.listview);
                lv.setAdapter(adapter);

                lv.setOnItemClickListener(new OnItemClickListener() {
                        public void onItemClick(AdapterView<?> parent, View 
view,
                                int position, long id) {

                            Cursor c = (Cursor) 
parent.getItemAtPosition(position);
                String department = c.getString(1); // Column index
                                Toast.makeText(getApplicationContext(),
                                        department + " is selected",
                                        Toast.LENGTH_SHORT).show();

                        // Create Spinner View object from layout resource
                        Spinner spinner = (Spinner) findViewById(R.id.spinner1);
                        if (spinner == null) {
                                Log.e(TAG, "Spinner object is null!");
                        }
                        SimpleCursorAdapter adapter = new
SimpleCursorAdapter(getBaseContext(),
                                android.R.layout.simple_spinner_item, // Use a
template
                                                                      // that
displays a
                                                                      // text 
view
                                c, // Give the cursor to the adapter
                                new String[] {"dname"}, // Map the NAME column 
in
the
                                                                     // 
department
database to...
                                new int[] {android.R.id.text1}); // The "text1" 
view
defined in
                                                                 // the XML 
template
                        if (adapter == null) {
                                Log.e(TAG, "Adapter object is null!");
                        }
        
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                        spinner.setAdapter(adapter);
                        spinner.setOnItemSelectedListener(new
MyOnItemSelectedListener());
                        }
                });

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to