How to show data in second spinner based on data chosen in first spinner?

Course Queries Syllabus Queries 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago


I am putting my data in spinners.Data is coming from URL.How to make spinner so that when syllabus is ICSE is chosen it reflect only those grade, subject which has ICSE?

My JSON

  {  
     "results":[  
  {  
     "syllabus":"CBSE",
     "grade":"5",
     "subject":"Kannada",
     "topic":"Grammar Level 1",
     "id":28
  },

  {  
     "syllabus":"CBSE",
     "grade":"5",
     "subject":"Science",
     "topic":"The Natural  Calamities",
     "id":16
  },


  {  
     "syllabus":"CBSE",
     "grade":"6",
     "subject":"Science",
     "topic":"Movement in Animals",
     "id":116
  },

  {  
     "syllabus":"CBSE",
     "grade":"6",
     "subject":"Social Studies",
     "topic":"Contact With Distant Lands",
     "id":59
  },

  {  
     "syllabus":"CBSE",
     "grade":"6",
     "subject":"Social Studies",
     "topic":"Gupta Empire",
     "id":34
  },   


  "id":148
  },
  {  
     "syllabus":"ICSE",
     "grade":"6",
     "subject":"Computers",
     "topic":"Introduction to QBASIC Programming",
     "id":44
  },


  {  
     "syllabus":"ICSE",
     "grade":"6",
     "subject":"Social Studies - History",
     "topic":"The Vedic Age",
     "id":42
  },
  {  
     "syllabus":"Entrance Exam - Karnataka CET",
     "grade":"12",
     "subject":"Mathematics",
     "topic":"Previous Year Question Papers",
     "id":121
  },
  {  
     "syllabus":"Entrance Exam - Karnataka CET",
     "grade":"12",
     "subject":"Science - Biology",
     "topic":"Previous Year Question Papers",
     "id":117
  },
  {  
     "syllabus":"Entrance Exam - Karnataka CET",
     "grade":"12",
     "subject":"Science - Chemistry",
     "topic":"Previous Year Question Papers",
     "id":110
  },
  {  
     "syllabus":"Entrance Exam - Karnataka CET",
     "grade":"12",
     "subject":"Science - Physics"
                                                
                                                
0 views
0 shares
profilepic.png
manpreet 2 years ago

Remove these lines first from doInBackground method. No need to create separate arraylist here..

worldlist.add(jsonobject.optString("syllabus"));
            worldlist2.add(jsonobject.optString("grade"));
            worldlist3.add(jsonobject.optString("subject"));

Declare these arraylist globally...

ArrayList<String> syllabuslist;
    ArrayList<String> gradlist;
    ArrayList<String> subjectlist;

and initialize these spinner in OnCreate method before calling Async task(DownloadJSON())

 Spinner mySpinner = (Spinner) findViewById(R.id.syllabus);
 Spinner mySpinner2 = (Spinner) findViewById(R.id.grade);
 Spinner mySpinner3 = (Spinner) findViewById(R.id.subject);

Now set spinner in onPostExecute() method....remove extra code you have written in onPostExcute...just copy my code

 @Override
    protected void onPostExecute(Void args) {

        // Spinner adapter
        syllabuslist = new ArrayList<String>();
        for (Results bean : world) {
            syllabuslist.add(bean.getSyllabus());
        }

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, syllabuslist);

        adapter
                .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        mySpinner.setAdapter(adapter);

        mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView arg0, View arg1,
                                       int arg2, long arg3) {

                String syllabus_name = mySpinner.getItemAtPosition(arg2).toString();


                gradlist = new ArrayList<String>();
                for (int i 
                                                    
                                                    
0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.