How to show second spinner data based on first spinner. Json is coming from url? Ask Question

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


Till now I am getting JSON and putting them in 3 different spinners. But the problem is that how to make 2nd spinner data based on the 1st spinner and 3rd spinner data based on the 2nd spinner.

       This is my code for JSON.

            try {
            // Locate the NodeList name
            jsonarray = jsonobject.getJSONArray("results");
            for (int i = 0; i < jsonarray.length(); i++) {
                jsonobject = jsonarray.getJSONObject(i);

                Results worldpop = new Results();

                worldpop.setSyllabus(jsonobject.optString("syllabus"));
                worldpop.setGrade(jsonobject.optString("grade"));
                worldpop.setSubject(jsonobject.optString("subject"));
                //worldpop.setFlag(jsonobject.optString("flag"));
                world.add(worldpop);


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

            }
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void args) {
        // Locate the spinner in activity_main.xml

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

        // Spinner adapter


        LinkedHashSet<String> listToSet = new LinkedHashSet<String>(worldlist);

        //Creating Arraylist without duplicate values
        final List<String> worldlistnew = new ArrayList<String>(listToSet);




     mySpinner
                .setAdapter(new ArrayAdapter<
                                                
                                                
0 views
0 shares
profilepic.png
manpreet 2 years ago


Here is the answer. In this example depending on first spinner second spinner values gets changes. and it will also change the text in the actitivty, which ever value you are selecting in second spinner. If this helps you please vote.

s://forum.tuteehub.com/tag/import">import android.os.Bundle;
s://forum.tuteehub.com/tag/import">import android.app.Activity;
s://forum.tuteehub.com/tag/import">import android.content.Intent;
s://forum.tuteehub.com/tag/import">import android.text.Html;
s://forum.tuteehub.com/tag/import">import android.view.Menu;
 s://forum.tuteehub.com/tag/import">import android.view.View.OnClickListener;
 s://forum.tuteehub.com/tag/import">import java.util.ArrayList;
s://forum.tuteehub.com/tag/import">import android.view.View;
s://forum.tuteehub.com/tag/import">import android.widget.AdapterView;
s://forum.tuteehub.com/tag/import">import android.widget.AdapterView.OnItemSelectedListener;
s://forum.tuteehub.com/tag/import">import android.widget.ArrayAdapter;
 s://forum.tuteehub.com/tag/import">import android.widget.Button;
 s://forum.tuteehub.com/tag/import">import android.widget.ImageView;
 s://forum.tuteehub.com/tag/import">import android.widget.Spinner;
 s://forum.tuteehub.com/tag/import">import android.widget.TextView;

 public class Courses extends Activity {




Spinner s1,s2;
TextView seats_t,t2,hod_det;
ImageView im1;
String s;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.courses);



    s1 = (Spinner) findViewById(R.id.grad);
    s2 = (Spinner) findViewById(R.id.streams);
    seats_t=(TextView)findViewById(R.id.about1);
    t2=(TextView)findViewById(R.id.hodname1);
    hod_det=(TextView)findViewById(R.id.hoddetails);
    im1=(ImageView)findViewById(R.id.hodimage);
    t2.setText
                                                    
                                                    
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.