Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Course Queries Syllabus Queries 2 years ago
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.
Turn Your Knowledge into Earnings.
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 REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
You need to use the Activity context this is not the activity context try like this
this
adapter= new ArrayAdapter<String>(Mainactivity.this, android.R.layout.simple_spinner_item, array);
Edit :
Change your array format. For example in your spinner you are going to show the subject so do the following
String[] mySubject = new String[array.length()]; for (int i = 0; i < array.length(); i++) { JSONObject person = (JSONObject) array .get(i); System.out.println(person.toString()); String syllabus = person.getString("grade"); String grade = person.getString("grade"); String subject = person.getString("subject"); jsonResponse += "Board: " + syllabus + "\n\n"; jsonResponse2 += "Class: " + grade + "\n\n"; jsonResponse3 += "Subject: " + subject + "\n\n"; // jsonResponse4 += "ID: " + id + "\n\n"; mySubject[i] = subject; } adapter= new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mySubject); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter);
Note : Also you need to move your set adapter outside of for loop.
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.
Course Queries 4 Answers
Course Queries 5 Answers
Course Queries 1 Answers
Course Queries 3 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.