Android Tutorial on Volley library – How to Fetching JSON Data from URL
Hey guys, welcome to Proto Coders Point. This Tutorial post is all about implementing Android Volley Library Tutorial. I have a URL on our website that gives me some JSON format data, and by using Volley library we will get those data, and we will also parse it. Ok So if you want to learn how to fetch json data from a URL in android and display it in Listview then let’s start this Android Tutorial on Volley library.
Before Starting Implementation let us know Basic of Volley Library.
What is Android Volley?
If you are new in android then you might be thinking what is this Volley library?
Volley is an HTTP library that makes networking very easy and fast, for Android application development.
What are benefits of Android Volley?
Easy to use request management
Fast in fetching data from Any network.
Efficient network management
Easily customizable according to our need.
Android Tutorial on Volley library Implementation in android Studio.
Demo Output of android volley Library project
android volley library tutorial project
Now it’s time for implement library, As i have told you above that i have a URL that contain JSON Data Format.
Then if you are implementing this project then you can use same URL for your project Practice or Create your own JSON Data.
If you open the above URL, you will see the following JSON DATA .
{
"superheros": [
{
"name": "Flash",
"power": "Speed Run :.............."
},
{
"name": "Super Man",
"power": "the powers of flight, ................."
},
{
"name": "Thor",
"power": "Superhuman strength, ........"
},
{
"name":"Hulk",
"power":"Incredible superhuman strength, ......."
},
{
"name":"Vemon",
"power":"Venom also has super strength — ........"
}
]
}
Now As you can see in above Screenshot Image we have some JSON data. At first, we have a JSON object { }, then inside that object, we have a key name superheros which contain array of JSON objects. Each object in the array has two more keys name and power. So In this android project our task is that to fetch this data and display it into a custom ListView.
Creating a new project under android-studio
As always the basic step in any development if creating a new Project.
when the project is been created successfully, we need to add uses-permission with INTERNET as we are about to perform a network Data fetch operation and it requires internet permission.
Adding internet Permission
Open the AndroidManifest.xml file under you project and you need to add internet permission as shown below.
For your application to work freely on Android Pie ( 9 ) and above you need to add uses-library org.apache.http.legacy inside application tag
Check out below screenshot for this
uses-library org.apache.http.legacy
Adding Volley Library
This is the very important step. As we are going to use volley library.
adding android volley library
navigate towords project
Gradle Scripts > build gradle (Module:app) > under dependencies add below lines of codes
As you can see that i have used ProgressBar that because when the fetching of data is going on we can show a progress bar until the data is fetched completed.
Then we would need a layout for our list items.
Inside the layout directory (res->layout) you need to create a new layout resource file and name it i have named it as list_items.xml.
Here we have two string items i.e (name and power) in our json data, So we created two TextViews here to display the fetched data here.
Creating a Custom Adapter for listview
For this you need to create a new java class,i have named it as ListViewAdapter.java and copy the below code in that java Adapter class .
package protocoderspoint.com.volleyandroidpractices;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
public class ListViewAdopter extends ArrayAdapter<SuperHero> {
//the hero list that will be displayed
private List<SuperHero> superHeroList;
//the context object
private Context mCtx;
//here we are getting the herolist and context
//so while creating the object of this adapter class we need to give herolist and context
public ListViewAdopter(List<SuperHero> superHeroList, Context mCtx) {
super(mCtx, R.layout.list_items, superHeroList);
this.superHeroList = superHeroList;
this.mCtx = mCtx;
}
//this method will return the list item
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//getting the layoutinflater
LayoutInflater inflater = LayoutInflater.from(mCtx);
//creating a view with our xml layout
View listViewItem = inflater.inflate(R.layout.list_items, null, true);
//getting text views
TextView textViewName = listViewItem.findViewById(R.id.textViewName);
TextView textViewImageUrl = listViewItem.findViewById(R.id.textViewPower);
//Getting the superHero for the specified position
SuperHero superHero = superHeroList.get(position);
//setting superHero values to textviews
textViewName.setText(superHero.getName());
textViewImageUrl.setText(superHero.getPower());
//returning the listitem
return listViewItem;
}
}
Now we are in the last part that is fetching and parsing the json and displaying it to the ListView.
Fetching JSON Data from URL
Open MainActivity.java file and paste the below lines of code.
package protocoderspoint.com.volleyandroidpractices;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
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.StringRequest;
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 {
//the URL having the json data
private static final String JSON_URL = "https://protocoderspoint.com/jsondata/superheros.json";
//listview object
ListView listView;
//the hero list where we will store all the hero objects after parsing json
List<SuperHero> superHeroList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initializing listview and hero list
listView = (ListView) findViewById(R.id.listView);
superHeroList = new ArrayList<>();
//this method will fetch and parse the data
loadHeroList();
}
private void loadHeroList() {
//getting the progressbar
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
//making the progressbar visible
progressBar.setVisibility(View.VISIBLE);
//creating a string request to send request to the url
StringRequest stringRequest = new StringRequest(Request.Method.GET, JSON_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//hiding the progressbar after completion
progressBar.setVisibility(View.INVISIBLE);
Log.d("Json Response",response);
try {
//getting the whole json object from the response
JSONObject obj = new JSONObject(response);
//we have the array named hero inside the object
//so here we are getting that json array
JSONArray heroArray = obj.getJSONArray("superheros");
//now looping through all the elements of the json array
for (int i = 0; i < heroArray.length(); i++) {
//getting the json object of the particular index inside the array
JSONObject heroObject = heroArray.getJSONObject(i);
//creating a superHero object and giving them the values from json object
SuperHero superHero = new SuperHero(heroObject.getString("name"), heroObject.getString("power"));
//adding the superHero to herolist
superHeroList.add(superHero);
}
//creating custom adapter object
ListViewAdopter adapter = new ListViewAdopter(superHeroList, getApplicationContext());
//adding the adapter to listview
listView.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//displaying the error in toast if occurrs
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
//creating a request queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//adding the string request to request queue
requestQueue.add(stringRequest);
}
}
In my sincere opinion – future seems shiny bright for Flutter. Time is ripe for alternate.
Java/Kotlin and Swift/objective-C lets in one to broaden handiest for Android and iOS respectively when it comes to developing apps.
however, Flutter framework opens doorways to cross-platform improvement surroundings. for this reason, very quickly human beings would want emigrate to a greater versatile platform, subsequently Flutter would upward thrust to glory.
future of flutter app developer
Tutorial I Purchased to learn Flutter – future
For getting to know app improvement, I followed more than one blogs, diverse Flutter programming and books, few video tutorials – both paid and loose.
However none could may want to make my sail a clean experience. It changed into only in March 2019 that I landed up on a video direction that modified the entirety for proper and brought me to pen this answer.
those who are searching ahead to learning cross-platform app development, i am bringing up the link to the course that helped me come to be an App Developer, you may locate it useful – The Complete 2020 Flutter Development Bootcamp with Dart
Which i have personally purchased and learn a lot about cross-platform app development as it as the future of flutter.
What you’ll learn in this flutter udemy course?
fast and native-quality apps with Flutter Build beautiful,
Become a fully-fledged Flutter developer
Build Android and iOS apps with just one codebase
Android and iOS apps building using just one programming language (Dart)
You can build a portfolio of Flutter apps to impress any Job recruiter
You will easily Understand all the fundamental concepts of Flutter Apps development
Become proficient in one of the fastest growing technologies
What is the future scope of Flutter?
I guess that the future scope is to become a successful cross-platform environment flutter for building great mobile apps for iOS, Android.
You want to be aware that for a brand new project like Flutter some things may want more work due to the fact no ready-to-use packages are to be had, however the Flutter community is quite energetic and new packages are added every day to Dart Package and i expect the frequency to growth loads when Flutter 1.0 will be release in all likelihood inside the no longer too far destiny.
In this tutorial i will show you how to make an Infinite Cycle View Pager with On Click Listner.
INFINITE CYCLE VIEW PAGER
Demo Screen Recorded
This Github Android Library comes with with two-way orientation i.e Horizontal and Vertical Orientation and interactive effect.
In a normal ViewPager, you are allowed only to scroll from the first page to second page until the last Page, from left-to-right. Once you reach the last page, your only option is to scroll backwards, right-to-left. In other words if we say from last page you cannot go back to first page directly, you need to scroll backwards until first page. Therefore I have found a infinite cycle ImageView Card ViewPager that solve the a problem.
Installation of Infinite Card ViewPager in project.
Let us now start adding required dependencies library into our android studio project.
Minimun SDK Version required for this library:
InfiniteCycleViewPager requires a minimum SDK version of 11.
Add Github Dependenices library in to Gradle (Module:app)
Hi Guys Welcome to Proto Coders Point, This project is a Beginner starting point for a Flutter application, Here we will see how can we implement webview in flutter web app development using webview plugin.
Demo on Flutter Webview
Video Tutorial – Convert Website to app
Introduction on Flutter WebView
Presenting a web view is pretty common in mobile apps. In Flutter, this is done by using the webview_flutter package.
Use this package Webview_Flutter as a library
If you want to use flutter webview widget you need to add some dependencies
Add this to your package’s pubspec.yamlfile:
dependencies:
webview_flutter: ^0.3.15+1
Then make sure with this indentation, sight empty space in pubspec.yaml file might give you error.
Import flutter webview widget package
Now in your Dart code (main.dart), you need to import widget packages, so that you can use flutter webview in you class file.
Let’s start implementing webview in your flutter application.
Create a new Flutter project in android studio.
creating-new-flutter-project-in-android-studio
Give a name to your flutter application. in my case i have name it as flutter_webview. you can name it anything it left to you.
So our flutter project is build and ready to implement our flutter code.
But then are flutter default code added into our flutter dart code. you can delete all the code from main.dart class and copy paste the code i provide you below.
First, the key parameter allows the Flutter widget tree to refer to this widget easily using a unique key created via Flutter’s UniqueKey() method you’ll soon see in the full example below.
javascriptMode simply allows us to control what kind of Javascript can be run in our web view.
Finally, initialUrl is the URL we want to display.
The important gotcha here is that we’ll need to use a StatefulWidget because it appears that if we use a StatelessWidget, the WebView will not load properly.
We pass in a url parameter to this widget, which is used in the state of our StatefulWidget.
In the app bar I have used 2 icons that will function as a back and forword button when we navigate to some other url in out webview onWebView controller will take care of this process.
Here there is also a reload button i.e floatingActionButton that will reload the initial url of the application.
Check Out Here’s How To Get Instagram Dark Mode Android Which makes Easier for Eye At Night
Facebook has followed the latest trend which is to introduce the Dark mode theme on Instagram too. Users with iOS and Android devices who are been using Instagram so far with normal instagram theme will now be able to experience the Dark mode of instagram. But as an update in official instagram, The feature may not be available to all users right away since it is being rolled out in phases.
Instagram automatically syncs your device and change it to the dark mode. The dark mode on Instagram will work only on iOS 13 and Android 10 devices. So before you go for it make sure that you have downloaded the latest version of Instagram.
How to put instagram dark mode android on Android phones
This is not a complicated process, but it may be a while until your Android phone has this feature. Why? Well, you need to have Android 10, the latest Android OS, to access Dark Mode on your phone.
Check if you already have Android 10 or if you can upgrade to it. To see if there is an upgrade available, go to Settings > System > System Update.
Once you’ve updated to Android 10, turn on your Dark Mode by going to Settings > Display > Dark Theme.
You can also turn on Dark Mode via Battery Saving Mode by going to Settings > Battery > Battery Saver. The two are connected now, as Dark Mode saves battery life, so if you switch on Battery Saver, you’ll automatically go to Dark Mode.
Open the Instagram app.
Dark Mode will be active in your Instagram app when you have it turned on in your phone settings, and you’ll be able to scroll with it until you turn of Dark Mode on your phone.
How to Get instagram dark mode on IOS Devices
Instagram automatically syncs your device and change it to the dark mode. The dark mode on Instagram will work only on iOS 13 and Android 10 devices. So before you go for it make sure that you have downloaded the latest version of Instagram.
iPhone iOS 13
Make Sure you iphone device is Updated the latest version of iOS 13.
Open the setting app on your device. Settings
Scroll down to the display and brightness option. Display & Brightness
There you will see the option of light mode and dark mode
Click on the dark mode option
Your iPhone will turn into the dark mode.
You can also click on the automatic option. The automatic option will automatically change the mode during daytime and night time.
Now you can enjoy the darkness!
Steps to change Iphone Instagram theme to dark mode.
Step 1 : Open Settings.
ios 13 setting screenshot
Step 2 : Go to Display & brightness
IOS dark mode theme Display and brightness
Step 3 : change as you need light mode or dark mode and per your requirement.
Flutter ListView
Long List
Memory Efficient
Dynamically
This Flutter Dart tutorial, Learn How to build an application with memory efficient Listview in dart by using ListView.Builder constructor. And dynamically inflate ListTile as the List element.
Steps to implement Flutter listview long list with memory efficient
1. Prepare a data source.
You need to prepare a data source which you want to inflate in each of the list item within your listview.
2. Convert data source into Widgets.
Then you need to convert the data source you have created or fetched from some out source into Widget because in the end, the flutter listview expects the array of widgets.
3. Use widgets as a children of a listview.
Finally you have to use all the widget as a children of the listview.
So let us follow the above steps & implement flutter listview dynamically.
1. Preparing a data source for flutter listview
Snippet code
List<String> getListElements() {
var items = List<String>.generate(1000, (counter) => "Item $counter"); // generate iten from 0 to 999
return items;
}
The above snippet code will simple generate list of items, which will be 1000 in number
Eg: item 0, item item 1 ,item 2,…………..item 999.
2. Converting data source into widget
Once your data source is ready you need to wrap it into your widget, so that i will define a method that will return the list view.
Where will genetare a listview, here is am using a constructor callede listview.builder,here one of the parameter of this builder constructor is a itemBuilder. Which helps us in creating items in our listview,here we have 2 parameter(context,index).
Right now i want all of the item to be inListTile,
There we are customizing title we are fetching from data source we have created above in steps 1.
Our Application has lots of Items to be displayed on the device screen but still out app is memory efficient just because Listview.builder function simply calls onlt for those elements that can be visible on the screen Therefore element which are hiding behind the screen are not been loaded into the memory thus it is memory efficient.
if you need to add further customize your listitems by using lending attribute like Icons,it is totally up to your wish what extra customization you want to make to your Flutter ListView application.