Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Load Database Intent to Spinner

android database intent

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1 DarkHeart

DarkHeart

    CC Newcomer

  • Member
  • PipPip
  • 16 posts

Posted 07 April 2015 - 09:55 AM

I have an Intent from a column in the database. I am wondering if/how i cant put the content from the intent into a spinner? Here is the code for how/where the intent comes from

DisplayStations.java

private void PopUpAlert(final long id) {
        Cursor cursor = dbHelper.getRow(id);

        if (cursor.moveToFirst()){

            //Preparing variables to use in message from Establishment record in Database
            String ID = cursor.getString(SQL.COL_STATION_ID);
            final String SName = cursor.getString(dbHelper.COL_STATION_NAME);
            String SType = cursor.getString(SQL.COL_STATION_TYPE);
            final String SFacility = cursor.getString(SQL.COL_FACILITIES_TYPE);
            String SLocation = cursor.getString(SQL.COL_LOCATION);
            String SEmail =  cursor.getString(SQL.COL_EMAIL);

            // building a drill down information message and displaying it in an Alert Dialog
            new AlertDialog.Builder(this)
                    .setTitle("Facilities Review App")
                    .setMessage("You Selected:\n"
                            + "Station ID: " + ID + "\n" + "Station Name: " + SName + "\n" +"Station Type: " + SType
                            + "\n" + "Facilities: " + SFacility + "\n" + "Location: " + SLocation
                            + "\n" + "Email: " + SEmail)
                    .setPositiveButton("Add Review", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // calling method to add a review for that particular establishment
                            addReviews(SName, SFacility);
                        }
                    })
                    .setNegativeButton("Delete", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // calling method to delete that particular establishment
                            deleteEstablishment(id, SName);

                        }


                    })
                    .setNeutralButton("List Reviews",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    // calling method to list reviews for the particular establishment


                                }


                            })
                    .show();
        }

    }

    private void addReviews(String SName, String SFacility) {
        Intent i = new Intent(getApplicationContext(), AddReview.class);
        i.putExtra("Stations", SName);
        Intent a = new Intent(getApplicationContext(), AddReview.class);
        a.putExtra("Stations", SFacility);
        startActivity(i);
    }

And here is the intent on the activity where i want the spinner to be

AddReview.java

 

Intent a = getIntent();
String Facility = a.getStringExtra("Stations");


#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 07 April 2015 - 05:38 PM

You can use put/getxxextra, or you can use the Application base class as a repository.

In your case, I would make an String array in the intent, and bring it bac with getStringArrayExtra().

 

The string array will work naturally with your spinner.



#3 DarkHeart

DarkHeart

    CC Newcomer

  • Member
  • PipPip
  • 16 posts

Posted 08 April 2015 - 12:42 AM

You can use put/getxxextra, or you can use the Application base class as a repository.

In your case, I would make an String array in the intent, and bring it bac with getStringArrayExtra().

 

The string array will work naturally with your spinner.

Thank you. Im fairly new to android app developement. Could me mind giving like some code snippets even? 



#4 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 12 April 2015 - 01:13 PM

this is a good example of ArrayList - Spinner






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download