in an android app . this is javacode to read api from web ,   import androidx.appcompat.app.AppCompatActivity;   import androidx.recyclerview.widget.LinearLayoutManager;   import androidx.recyclerview.widget.RecyclerView;       import android.os.Bundle;   import android.view.LayoutInflater;   import android.view.View;   import android.view.ViewGroup;   import android.widget.TextView;   import android.widget.Toast;       import com.android.volley.Request;   import com.android.volley.RequestQueue;   import com.android.volley.Response;   import com.android.volley.VolleyError;   import com.android.volley.toolbox.JsonObjectRequest;   import com.android.volley.toolbox.Volley;       import org.json.JSONArray;   import org.json.JSONException;   import org.json.JSONObject;       import java.util.ArrayList;   import java.util.List;       public class MainActivity extends AppCompatActivity {       privateList universityList;       @Override   protectedvoidonCreate(Bundle savedInstanceState){   super.onCreate(savedInstanceState);   setContentView(R.layout.activity_main);       universityList = new ArrayList<>();       String url ="http://universities.hipolabs.com/search?country=Canada";       JsonObjectRequest request =newJsonObjectRequest(Request.Method.GET, url,null,   newResponse.Listener(){   @Override   publicvoidonResponse(JSONObject response){   try{   JSONArray jsonArray = response.getJSONArray("data");       for(int i =0; i < jsonArray.length(); i++){   JSONObject jsonObject = jsonArray.getJSONObject(i);       String name = jsonObject.getString("name");   String province = jsonObject.getString("state-province");   String webPage = jsonObject.getString("web_page");       University university =newUniversity(name, province, webPage);   universityList.add(university);   }       RecyclerView recyclerView =findViewById(R.id.recyclerView);   recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));   UniversityAdapter adapter =newUniversityAdapter(universityList);   recyclerView.setAdapter(adapter);       }catch(JSONException e){   e.printStackTrace();   }   }   },newResponse.ErrorListener(){   @Override   publicvoidonErrorResponse(VolleyError error){   Toast.makeText(MainActivity.this,"Error fetching data",Toast.LENGTH_SHORT).show();   }   });       // Add the request to the RequestQueue   RequestQueue queue =Volley.newRequestQueue(this);   queue.add(request);   }       privatestaticclassUniversity{   privateString name;   privateString province;   privateString webPage;       publicUniversity(String name,String province,String webPage){   this.name = name;   this.province = province;   this.webPage = webPage;   }       publicStringgetName(){   return name;   }       publicStringgetProvince(){   return province;   }       publicStringgetWebPage(){   return webPage;   }   }       privatestaticclassUniversityAdapterextendsRecyclerView.Adapter{       privateList universityList;       publicUniversityAdapter(List universityList){   this.universityList = universityList;   }       @Override   publicViewHolderonCreateViewHolder(ViewGroup parent,int viewType){   View view =LayoutInflater.from(parent.getContext()).inflate(R.layout.university_item, parent,false);   returnnewViewHolder(view);   }       @Override   publicvoidonBindViewHolder(ViewHolder holder,int position){   University university = universityList.get(position);   holder.nameTextView.setText(university.getName());   holder.provinceTextView.setText(university.getProvince());   holder.webPageTextView.setText(university.getWebPage());   }       @Override   publicintgetItemCount(){   return universityList.size();   }       publicstaticclassViewHolderextendsRecyclerView.ViewHolder{   TextView nameTextView;   TextView provinceTextView;   TextView webPageTextView; '-- create a xml   code that can display Name, Province and Web Page Address of the universities and colleges in Canada from this API.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
in an android app . this is javacode to read api from web ,
 
import androidx.appcompat.app.AppCompatActivity;
 
import androidx.recyclerview.widget.LinearLayoutManager;
 
import androidx.recyclerview.widget.RecyclerView;
 
 
 
import android.os.Bundle;
 
import android.view.LayoutInflater;
 
import android.view.View;
 
import android.view.ViewGroup;
 
import android.widget.TextView;
 
import android.widget.Toast;
 
 
 
import com.android.volley.Request;
 
import com.android.volley.RequestQueue;
 
import com.android.volley.Response;
 
import com.android.volley.VolleyError;
 
import com.android.volley.toolbox.JsonObjectRequest;
 
import com.android.volley.toolbox.Volley;
 
 
 
import org.json.JSONArray;
 
import org.json.JSONException;
 
import org.json.JSONObject;
 
 
 
import java.util.ArrayList;
 
import java.util.List;
 
 
 
public class MainActivity extends AppCompatActivity {
 
 
 
privateList<University> universityList;
 
 
 
@Override
 
protectedvoidonCreate(Bundle savedInstanceState){
 
super.onCreate(savedInstanceState);
 
setContentView(R.layout.activity_main);
 
 
 
universityList = new ArrayList<>();
 
 
 
String url ="http://universities.hipolabs.com/search?country=Canada";
 
 
 
JsonObjectRequest request =newJsonObjectRequest(Request.Method.GET, url,null,
 
newResponse.Listener<JSONObject>(){
 
@Override
 
publicvoidonResponse(JSONObject response){
 
try{
 
JSONArray jsonArray = response.getJSONArray("data");
 
 
 
for(int i =0; i < jsonArray.length(); i++){
 
JSONObject jsonObject = jsonArray.getJSONObject(i);
 
 
 
String name = jsonObject.getString("name");
 
String province = jsonObject.getString("state-province");
 
String webPage = jsonObject.getString("web_page");
 
 
 
University university =newUniversity(name, province, webPage);
 
universityList.add(university);
 
}
 
 
 
RecyclerView recyclerView =findViewById(R.id.recyclerView);
 
recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
 
UniversityAdapter adapter =newUniversityAdapter(universityList);
 
recyclerView.setAdapter(adapter);
 
 
 
}catch(JSONException e){
 
e.printStackTrace();
 
}
 
}
 
},newResponse.ErrorListener(){
 
@Override
 
publicvoidonErrorResponse(VolleyError error){
 
Toast.makeText(MainActivity.this,"Error fetching data",Toast.LENGTH_SHORT).show();
 
}
 
});
 
 
 
// Add the request to the RequestQueue
 
RequestQueue queue =Volley.newRequestQueue(this);
 
queue.add(request);
 
}
 
 
 
privatestaticclassUniversity{
 
privateString name;
 
privateString province;
 
privateString webPage;
 
 
 
publicUniversity(String name,String province,String webPage){
 
this.name = name;
 
this.province = province;
 
this.webPage = webPage;
 
}
 
 
 
publicStringgetName(){
 
return name;
 
}
 
 
 
publicStringgetProvince(){
 
return province;
 
}
 
 
 
publicStringgetWebPage(){
 
return webPage;
 
}
 
}
 
 
 
privatestaticclassUniversityAdapterextendsRecyclerView.Adapter<UniversityAdapter.ViewHolder>{
 
 
 
privateList<University> universityList;
 
 
 
publicUniversityAdapter(List<University> universityList){
 
this.universityList = universityList;
 
}
 
 
 
@Override
 
publicViewHolderonCreateViewHolder(ViewGroup parent,int viewType){
 
View view =LayoutInflater.from(parent.getContext()).inflate(R.layout.university_item, parent,false);
 
returnnewViewHolder(view);
 
}
 
 
 
@Override
 
publicvoidonBindViewHolder(ViewHolder holder,int position){
 
University university = universityList.get(position);
 
holder.nameTextView.setText(university.getName());
 
holder.provinceTextView.setText(university.getProvince());
 
holder.webPageTextView.setText(university.getWebPage());
 
}
 
 
 
@Override
 
publicintgetItemCount(){
 
return universityList.size();
 
}
 
 
 
publicstaticclassViewHolderextendsRecyclerView.ViewHolder{
 
TextView nameTextView;
 
TextView provinceTextView;
 
TextView webPageTextView;
'--
create a xml   code that can display Name, Province and Web Page Address of the universities and colleges in Canada from this API.
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Java
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education