Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education