Skip to main content

Posts

Showing posts from October, 2020

android kotlin - Volley JsonArrayRequest

Android Kotlin - Volley JsonArrayRequest: Summary This code demonstrates fetching a JSON array from a URL and displaying its content in a scrollable TextView using Volley, a popular Android networking library. The user clicks a button to trigger the request, and the response is parsed to extract student data (first name, last name, and age). This data is then displayed in a formatted way within the TextView. Android Kotlin - Volley JsonArrayRequest: Breakdown The code is divided into three parts: MainActivity.kt: This is the main activity class that handles user interaction and network requests. It defines the layout elements (button, progress bar, and text view) and their functionalities. When the button is clicked, it: Disables the button to prevent multiple clicks. Shows the progress bar to indicate ongoing network activity. Creates a JsonArrayRequest object specifying the URL, method (GET), success and error listeners. Adds the request to Volley's request q...

android kotlin - Volley JsonObjectRequest

Introduction This code demonstrates how to fetch a JSON object from a URL using Volley, a popular networking library for Android development written in Kotlin. The code is divided into three parts: MainActivity.kt: This file is the core activity class that handles user interaction and network requests. VolleySingleton.kt: This file implements a singleton class to manage the Volley request queue, ensuring only one instance exists throughout the application. activity_main.xml: This file defines the user interface layout of the main activity with a button, a progress bar, and a text view. Breakdown of MainActivity.kt The MainActivity class: Initializes UI elements (button, progress bar, text view) by referencing their IDs from the layout file. Defines a URL containing a JSON object with an array of student information. Implements a click listener for the button: Disables the button to prevent multiple requests. Shows the progress bar to indicate network activity. Creates ...