Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

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

Course Queries Syllabus Queries
Max. 2000 characters
Replies

usr_profile.png
Shreya Bansal

User

( 6 months 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"
								 								 
							usr_profile.png
							
Atul Kasana

User

( 6 months 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 = 
			
        

what's your interest