How to put Json data in spinners from URL?

Course Queries Syllabus Queries 3 years ago

2.1K 1 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

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


I am getting my json in text box I tried to put those data in spinner but unable to do so. Below is my main activity class and I am using Volley.

    public class Mainactivity  extends Activity {
        private String urlJsonArry = "https://www.abc.json";
        private static String TAG = MainActivity.class.getSimpleName();
        private Button btnMakeArrayRequest;

        // Progress dialog
        private ProgressDialog pDialog;

        private TextView txtResponse,txtResponse2,txtResponse3,txtResponse4;

        // temporary string to show the parsed response
        private String jsonResponse, jsonResponse2, jsonResponse3, jsonResponse4;
        Spinner spinner;
        ArrayAdapter<String> adapter;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.spinners);

            spinner= (Spinner) findViewById(R.id.spinner);




            btnMakeArrayRequest = (Button) findViewById(R.id.btnArrayRequest);
            txtResponse = (TextView) findViewById(R.id.txtResponse);
            txtResponse2 = (TextView) findViewById(R.id.txtResponse2);
            txtResponse3 = (TextView) findViewById(R.id.txtResponse3);
            //  txtResponse4 = (TextView) findViewById(R.id.txtResponse4);


            pDialog = new ProgressDialog(this);
            pDialog.setMessage("Please wait...");
            pDialog.setCancelable(false);

            btnMakeArrayRequest.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // making json array request
                    makeJsonArrayRequest();
                }
            });

        }



        private void makeJsonArrayRequest () {

        showpDialog();
        JsonObjectRequest req = new JsonObjectRequest(urlJsonArry,

                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d
                                                
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.

Similar Forum