Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i put you here my solution for handle two json using lisview;</p> <pre><code>public class ListViewer extends ListActivity{ //Primary URL JSON1 private static String url0 = "http:/a.com/url"; //URL JSON2 private static String url2 = "http:/a.com/url"; //JSON1 Node names public static final String TAG_COURSES1 = "Courses"; //JSONArray from json1 public static final String TAG_COURSEID1 = "CourseId"; //Object from json1 - Array courses public static final String TAG_RATING1 = "Rating"; //Object from json1 - Array courses public static final String TAG_STATUS1 = "Status"; //Object from json1 - Array courses // JSON2 Node names public static final String TAG_COURSES2 = "Courses"; //JSONArray from json2 public static final String TAG_COURSEID2 = "CourseId"; //Object from json2 - Array courses public static final String TAG_TITLE = "title"; //Object from json2 - Array courses public static final String TAG_INSTRUCTOR = "instructor"; //Object from json2 - Array courses public static final String TAG_LENGTH = "length"; //Object from json2 - Array courses public static final String TAG_RATING2 = "Rating"; //Object from json2 - Array courses public static final String TAG_SUBJECT = "subject"; //Object from json2 - Array courses public static final String TAG_DESCRIPTION = "description"; //Object from json2 - Array courses public static final String txt_instructor = "Instructor: "; public static final String txt_length = "Length: "; public static final String txt_minutes = "minutes"; //Course JSONArray's from json1 &amp; json2 = null, for now. JSONArray Courses1 = null; JSONArray Courses2 = null; //Lists public ListView list1; public ListView list2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.lay_main); // Hashmap for ListView ArrayList&lt;HashMap&lt;String, String&gt;&gt; coursesList1 = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); ArrayList&lt;HashMap&lt;String, String&gt;&gt; coursesList2 = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); //Getting bundles 3 &amp; 4, from MariposaTrainingActivity.class... Bundle bundle1 = getIntent().getExtras(); String userName=bundle1.getString("UN"); //Getting the userName Bundle bundle2 = getIntent().getExtras(); String password=bundle2.getString("PW"); //Getting the passord String UR = "UserName="; //String for build the url1, for the request json1. String QTE = "&amp;"; //String for build the url1, for the request json1. String PW = "Password="; //String for build the url1, for the request json1. //Building the URL to get the json1. String url1 = url0 + UR + userName + QTE + PW + password; // Creating JSON Parser instance (json1) JSONParser2 jParser1 = new JSONParser2(); // getting JSON string from URL (json1) final JSONObject json1 = jParser1.getJSONFromUrl(url1); // Creating JSON Parser instance (json2) JSONParser2 jParser2 = new JSONParser2(); // getting JSON string from URL (json2) final JSONObject json2 = jParser2.getJSONFromUrl(url2); try { // Getting The Array "Courses" from json1 &amp; json2 Courses1 =json1.getJSONArray(TAG_COURSES1); Courses2 = json2.getJSONArray(TAG_COURSES2); int x = 1; //LOOP FOR JSON1 for(int i = 0; i &lt; Courses1.length(); i++){ //LOOP FOR JSON2 for(int ii = 0; ii &lt; Courses2.length(); ii++){ JSONObject courses1 = Courses1.getJSONObject(i); JSONObject courses2 = Courses2.getJSONObject(ii); // Storing each json1 item in variable int courseID1 = courses1.getInt(TAG_COURSEID1); //Log.e("COURSEID1:", Integer.toString(courseID1)); String Rating1 = courses1.getString(TAG_RATING1); int Status1 = courses1.getInt(TAG_STATUS1); //Log.e("Status1:", Integer.toString(Status1)); //Put the actual value for Status1 in log. // Storing each json2 item in variable int courseID2 = courses2.getInt(TAG_COURSEID2); //Log.e("COURSEID2:", Integer.toString(courseID2)); //Put the actual value for CourseID2 in log String Title2 = courses2.getString(TAG_TITLE); String instructor2 = courses2.getString(TAG_INSTRUCTOR); String length2 = courses2.getString(TAG_LENGTH); String rating2 = courses2.getString(TAG_RATING2); String subject2 = courses2.getString(TAG_SUBJECT); String description2 = courses2.getString(TAG_DESCRIPTION); //Status1 = 5 from json1; Incomplete, Status1 =-1 Complete if(courseID2 == courseID1){ int x1 = x++; //Get the count for All values. //Log.e("x=", Integer.toString(x1)); //Show the value in Logcat. // Get pairs/odds. int Num = x1 % 2; //Log.e("Num=", Integer.toString(Num)); // //Creating new HashMap HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); HashMap&lt;String, String&gt; map2 = new HashMap&lt;String, String&gt;(); if(Num==1){ map.put(TAG_COURSEID2, Integer.toString(courseID2)); map.put(TAG_TITLE, Title2); map.put(txt_instructor, "Instructor: "); map.put(TAG_INSTRUCTOR, instructor2); map.put(txt_length, "Length: "); map.put(TAG_LENGTH, length2); map.put(txt_minutes, " minutes"); map.put(TAG_RATING2, rating2); map.put(TAG_SUBJECT, subject2); map.put(TAG_DESCRIPTION, description2); //adding HashList to ArrayList coursesList1.add(map); } if(Num==0) { map2.put(TAG_COURSEID2, Integer.toString(courseID2)); map2.put(TAG_TITLE, Title2); map2.put(txt_instructor, "Instructor: "); map2.put(TAG_INSTRUCTOR, instructor2); map2.put(txt_length, "Length: "); map2.put(TAG_LENGTH, length2); map2.put(txt_minutes, " minutes"); map2.put(TAG_RATING2, rating2); map2.put(TAG_SUBJECT, subject2); map2.put(TAG_DESCRIPTION, description2); //adding HashList to ArrayList coursesList2.add(map2); } }//if }//for2 (json2) } //for1 (json1) }//Try catch (JSONException e) { e.printStackTrace(); } ListAdapter adapter2 = new SimpleAdapter(this, coursesList2, R.layout.list_courses_2, new String[] { TAG_COURSEID2, TAG_TITLE, txt_instructor, TAG_INSTRUCTOR, txt_length, TAG_LENGTH, txt_minutes, TAG_RATING2, TAG_SUBJECT, TAG_DESCRIPTION }, new int[] { R.id.txt_courseid_r2, R.id.txt_title_r2, R.id.txt_text_instructor_r2, R.id.txt_instructor_r2, R.id.txt_text_length_r2,R.id.txt_length_r2, R.id.txt_text_minutes_r2,R.id.txt_rating_r2, R.id.txt_topic_r2, R.id.txt_description_r2 }); setListAdapter(adapter2); colectorXML2(); list2.setAdapter(adapter2); list2.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // getting values from selected ListItem String courseID = ((TextView) view.findViewById(R.id.txt_courseid_r2)).getText().toString(); String Title = ((TextView) view.findViewById(R.id.txt_title_r2)).getText().toString(); String instructor = ((TextView) view.findViewById(R.id.txt_instructor_r2)).getText().toString(); String length = ((TextView) view.findViewById(R.id.txt_length_r2)).getText().toString(); String rating = ((TextView) view.findViewById(R.id.txt_rating_r2)).getText().toString(); String subject = ((TextView) view.findViewById(R.id.txt_topic_r2)).getText().toString(); String description = ((TextView) view.findViewById(R.id.txt_description_r2)).getText().toString(); // Starting new intent Intent in = new Intent(getApplicationContext(), SingleListItem.class); in.putExtra(TAG_COURSEID2, courseID); in.putExtra(TAG_TITLE, Title); in.putExtra(TAG_INSTRUCTOR, instructor); in.putExtra(TAG_LENGTH, length); in.putExtra(TAG_RATING2, rating); in.putExtra(TAG_SUBJECT, subject); in.putExtra(TAG_DESCRIPTION, description); startActivity(in); } });//lv.SetOnclickListener ListAdapter adapter = new SimpleAdapter(this, coursesList1, R.layout.list_courses, new String[] { TAG_COURSEID2, TAG_TITLE, txt_instructor, TAG_INSTRUCTOR, txt_length, TAG_LENGTH, txt_minutes, TAG_RATING2, TAG_SUBJECT, TAG_DESCRIPTION }, new int[] { R.id.txt_courseid, R.id.txt_title, R.id.txt_text_instructor, R.id.txt_instructor, R.id.txt_text_length,R.id.txt_length, R.id.txt_text_minutes,R.id.txt_rating, R.id.txt_topic, R.id.txt_description }); colectorXML(); list1.setAdapter(adapter); // Launching new screen on Selecting Single ListItem list1.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // getting values from selected ListItem String courseID = ((TextView) view.findViewById(R.id.txt_courseid)).getText().toString(); String Title = ((TextView) view.findViewById(R.id.txt_title)).getText().toString(); String instructor = ((TextView) view.findViewById(R.id.txt_instructor)).getText().toString(); String length = ((TextView) view.findViewById(R.id.txt_length)).getText().toString(); String rating = ((TextView) view.findViewById(R.id.txt_rating)).getText().toString(); String subject = ((TextView) view.findViewById(R.id.txt_topic)).getText().toString(); String description = ((TextView) view.findViewById(R.id.txt_description)).getText().toString(); // Starting new intent Intent in = new Intent(getApplicationContext(), SingleListItem.class); in.putExtra(TAG_COURSEID2, courseID); in.putExtra(TAG_TITLE, Title); in.putExtra(TAG_INSTRUCTOR, instructor); in.putExtra(TAG_LENGTH, length); in.putExtra(TAG_RATING2, rating); in.putExtra(TAG_SUBJECT, subject); in.putExtra(TAG_DESCRIPTION, description); startActivity(in); } });//lv.SetOnclickListener }//onCreate private void colectorXML() { list1 = (ListView)findViewById(android.R.id.list); } private void colectorXML2() { list2 =(ListView)findViewById(R.id.list2); } }// Activity </code></pre> <p>Just put your methods, and your json info, in this case you just handle 1 json, so make the rest... Hope this give you ideas.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload