Saturday , June 25 2022

Filter JSON Data in Android Application using PHP and MySQL – Android Coding by DMTechnolab

The package With.Examples.Manish.jsonfilterapp;

Import Android.App.Progressressialog;

Import Android.Content.Context;

Import Android.Content.Intent;

Import Android.Content.Sharing;

Import Android.Support.v7.App.AppCompatActivity;

Import Android..Bundle;

Import Android.Opinion.Opinion;

Import Android.Widget.switch;

Import Android.Widget.list View;

Import Android.Widget.text view;

Import Android.Widget.Toast;

Import With.Android.Volley.Request;

Import With.Android.Volley.request;

Import With.Android.Volley.Feedback;

Import With.Android.Volley.VolleyError;

Import With.Android.Volley.Toolbox.Stringering;

Import With.Android.Volley.Toolbox.Volley;

Import org.Jasan.JSONArray;

Import org.Jasan.JSONException;

Import org.Jasan.JSONObject;

Import Java.Useful.array list;

Import Java.Useful.Collection;

Import Java.Useful.Comparable;

Import Java.Useful.Hashset;

Import Java.Useful.The list;

Import Java.Useful.The set;

public class Main activity Is spread AppCompatActivity come into force Opinion.OnClickListener {{

switch Buttonlist,Buttonsbrandbrand,buttonSbbyprice,Buttonfilters;

Progressressialog PragatiDialogue;

text view text view; Sharing Shared vision;

String URL = “Your URL for GetData.php”;

String mn;

LaptopAdapter Laptop adapter;

array list<The laptop> Laptop maker= = New array list<The laptop>());

String jsonString;


Protected Zero Go ahead()Bundle saveInstanceState) {{

Super.Go ahead()saveInstanceState);


PragatiDialogue = = New Progressressialog()this);

Buttonfilters = = ()switch) findViewById()R.Id.Buttonfilters);

Buttonsbrandbrand = ()switch) findViewById()R.Id.Buttonsbrandbrand);

buttonSbbyprice = = ()switch) findViewById()R.Id.buttonSbbyprice);

Buttonlist = ()switch) findViewById()R.Id.Buttonlist);






Shared vision = getSaredPreferences()“SHARED_PREF_NAME”, Context.MODE_PRIVATE);



public Zero on click()Opinion v) {{


Beginning()New Intent()this,Impermanence.class));



Beginning()New Intent()this,Sortbrand.class));



Beginning()New Intent()this,SortBedPrice.class));



Beginning()New Intent()this,Filtration.class));



public Zero getLaptops()) {{

PragatiDialogue.Set message()“Fetching data from server …”);


Stringering Rigid = New Stringering()Request.way.Post, URL,

New Feedback.Listner<String>()) {{


public Zero Treason()String Feedback) {{


Toast.Makeup()Main activity.this, “Data successfully received”, Toast.LENGTH_SHORT).Display());

try {{

JSONObject Js = = New JSONObject()Feedback);

JSONArray jsonArray = = Js.getJSONArray()“Laptop”);

jsonString = = jsonArray.Wire());

Sharing.Editor Editor = Shared vision.Edit()); put()“jsonString”,jsonString);


JSONArray SortedJsonArray = New JSONArray());

The list<JSONObject> jsonValues = = New array list<JSONObject>());

For ()int I am = 0; I am < jsonArray.Length()); I am++) {{

jsonValues.Add up()jsonArray.getJSONObject()I am));


Collection.Serialize() jsonValues, New Comparable<JSONObject>()) {{

// You can replace “name” with “id” if you want to sort by ID

Private Fixed The last String KEY_NAME = “model name”;


public int Compare()JSONObject a, JSONObject B) {{

String valA = = New String());

String valB = = New String());

try {{

valA = = ()String) a.get()KEY_NAME);

valB = = ()String) B.get()KEY_NAME);


Hold ()JSONException I) {{

//do something


The return to()valB);

// If you want to change the sort order, just use the following:

// return -valA.compareTo (valB);



For ()int I am = 0; I am < jsonArray.Length()); I am++) {{

SortedJsonArray.Branch()jsonValues.get()I am));


} Hold ()JSONException I) {{





New Feedback.Error maker()) {{


public Zero onErrorResponse()VolleyError Error) {{



request Request = Volley.newRequestQueue()this);

Request.Add up()Rigid);



Source link

About dmtechnolab

Check Also

Simplified Coding

Android Hilt Tutorial – Injecting Dependencies with Hilt – Android Coding by DMTechnolab

You are welcome Android Hilt tutorial. I hope you all are aware of it Dependency …

One comment

  1. Hello there, I discovered your web site by the use of
    Google at the same time as searching for a comparable subject, your website came up,
    it looks great. I have bookmarked it in my google bookmarks.

    Hi there, just become aware of your weblog via Google, and located
    that it is truly informative. I am gonna be careful for brussels.
    I’ll be grateful if you happen to continue this in future.
    A lot of other people can be benefited from your writing.

Leave a Reply

Your email address will not be published. Required fields are marked *