Skip to main content

Posts

Recent posts

Building Query String in Android

This is pretty interesting. Simply do this. Press Alt + enter to remove the Red lined error messages. It works. It helps to send get Params as Query String. Uri.Builder builder = new Uri.Builder(); builder.scheme( "http" ) .authority( "kmdahousing.in" ) .appendPath( "ApiController" ) .appendPath( "complaints" ) .appendQueryParameter( "UID" , String. valueOf (userID)); String URL = builder.build().toString();

[Solved] Formatting Date & Time in Android App using Java | Java SimpleDateFormat Live Example

 This is bit tricky. Those familiar with Java, please ignore. Those not, please continue reading how to fix date format using java. Here challenge is that we have fetched record from mySQL Database. Here date is typically stored in yyyy-mm-dd hh:ii:ss format. Ex. 2021-01-26 12:22:31 The logical flow is important to understantd. 1. MySQL returns a string as date. 2. We convert this strDate to Date Format. 3. Now we change the date format to desired formatting. 4. Next we convert the date to string again. 5. Finally we return the newly formatted date string. The code blocks:- String dateCreated = "2021-01-26 12:22:05"; String formattedDate = null ; try { formattedDate = getFormattedDate (dateCreated); } catch (ParseException e) { e.printStackTrace(); } Toast.makeText(this, formattedDate,LENGTH_SHORT).show(); /* Now create a function */    public static String getFormattedDate(String strDate) throws ParseException { Date date = new SimpleDateFormat( "yyyy-MM-dd ...

Android RecyclerView Tutorial - Fetching JSON

First add dependencies to android file   Add recyclerview library in build.gradle file implementation 'androidx.recyclerview:recyclerview:1.1.0' Step 2 activity_complaints.xml This XML file holds recyclerview component <? xml version ="1.0" encoding ="utf-8" ?> < androidx.recyclerview.widget.RecyclerView xmlns: android ="http://schemas.android.com/apk/res/android" android :layout_height ="match_parent" android :layout_width ="match_parent" android :id ="@+id/rvComplaintsList" > </ androidx.recyclerview.widget.RecyclerView > Step 3 This will contain Components to be repeated via RecyclerView. complainsts_list_layout.java <? xml version ="1.0" encoding ="utf-8" ?> < LinearLayout xmlns: android ="http://schemas.android.com/apk/res/android" android :orientation ="horizontal" android :layout_width ="match_parent" and...

How to Align Views at The Bottom of The Screen

This is h ow you can Align Views at The Bottom of The Screen You know, you have to go to layout_main.xml file (If this is the layout you want to tweak with). Here we add a LinearLayout Component. Then place a TextView Component within that liner layout. Most important note: Add android:gravity="bottom" in the LinearLayout Component Add  android :gravity ="center_horizontal" in the TextView Component You are done! Here goes your SAMPLE code. < LinearLayout android :layout_width ="match_parent" android :layout_height ="match_parent" android :gravity ="bottom" android :orientation ="horizontal" > < TextView android :id ="@+id/bottomText" android :layout_width ="match_parent" android :padding ="2dp" android :textSize ="18sp" android :layout_height ="wrap_content" android :background ="@color/cardview_...

Creating Options Menu with Sub Items - Android Studio Tutorial

Step 1 Go to res -> drawable -> New -> Vector Asset -> Select Menu Icon -> Give it suitable name res -> new -> Android Resource Directory  Select Resource Type = Menu Give a suitable name, we used topnav_menu  Add Menu Items to topnav_menu <? xml version ="1.0" encoding ="utf-8" ?> < menu xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" > < item android :id ="@+id/item1" android :icon ="@drawable/ic_right_arrow" android :title ="Item 1" app :showAsAction ="never" > </ item > < item android :id ="@+id/item2" android :icon ="@drawable/ic_right_arrow" android :title ="Item 2" app :showAsAction ="never" > </ item > < item android :id ="@+id/item3" android :icon ="@drawable/i...