Skip to main content

Posts

Showing posts from January, 2021

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...

Put & Get Values with Intent | Sharing Data between Activities | Android Tutorial

 Sharing data between activities in Android is as simple as this. Put Data Intent intent = new Intent(MainActivity. this , BrowseActivity. class ); intent.putExtra( "targetUrl" , "https://www.google.com" ); startActivity(intent); Get Data Intent intent = getIntent(); String targetUrl = intent.getStringExtra( "targetUrl" ); Here we put data in one activity. And retrieve the data in another activity. So, we need to .java files. Say, you have FirstActivity.java and SecondActivity.java file. You put values in FirstActivity.java file. So, code to put data should go in this file: Intent intent = new Intent(MainActivity. this , BrowseActivity. class ); intent.putExtra( "targetUrl" , "https://www.google.com" ); startActivity(intent); Now you retrieve the values in SecondActivity.java file. To retrieve information, use Intent intent = getIntent(); String targetUrl = intent.getStringExtra( "targetUrl" ); This is really simple. Obviously...

Android Browser - WebView - Complete Tutorial | Open a Web Page in Your Android App

  Let's learn details of WebView. While there are great YouTube videos to get you through the entire process, but it is always handy to get some code to copy-paste. This is the purpose why I maintain this blog. This is for my own assistance. Now, if you find it useful, it will be of great help for me. Now let us add a new empty activity. Name it as BrowserActivity. Write the following codes in activity_browser.xml <? xml version ="1.0" encoding ="utf-8" ?> < LinearLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_parent" android :layout_height ="match_parent" tools :context =".BrowseActivity" android :orientation ="vertical" > < LinearLayout android :layout_width ="match_parent" ...

WHAT IS AN INTENT IN ANDROID | EXPLICIT AND IMPLICIT INTENT TUTORIAL

 1. Intent helps to jump from one Activity to anther Activity 2. Create a Single Page Application with a Single Page (Activity) 3. Create another Page, i.e., Second Page (Second Activity) 4. Intent is an object which requests an Action from another object 5. Explicit Intent: Communicates between two activities within the same application 6. Implicit Intent: Communicates between two activities from two different applications 7. Intents are used to     1. Start activity     2.  Start services     3. Broadcasting Message    4.  Pass information The Code StartActivity(i);  Here  intent  is an object of type intent. This code is to be written in MainActivity.java file within setOnClickListener() Intent intent = new Intent(MainActivity. this , BrowseActivity. class ); startActivity(intent); The complete CodeBlock Goes Here btn_payment .setOnClickListener( new View.OnClickListener() { @Override public void onClick(Vi...

Modern Dashboard UI Design Android Studio Tutorial

Go to Build.gradle file  Add  implementation 'androidx.cardview:cardview:1.0.0' Open activity_main.xml Make changes as per your desired layout. User RelativeLayout, ScrollView, CardView and different other android:layout properties to arrange your layout as per requirement. It will be easier to try out different things initially to adjust settings and view its impact. Two things to remember while trying out different layouts: Use unique IDs for each layout element so that you can identify the items earmarked by respective IDs using findViewById() function. Make best use of different alignment properties like layout_width, layout_height, layout_marginTop, layout_marginBottom etc A note of different layouts in most simple words RelativeLayout: Used to align other layout elements like TextView / ImageView ScrollView: This is required to allow scrolling of Android Desktop CardView: A beautiful design element, used as a container for ImageView / TextView etc ImageView: Pl...

Create Splash Screen or Welcome Screen in Android

 To create Splash Screen for your Android App Create Handler Class Use PostDelayed() function Use Runnable (Code) & Time Delay Steps: A) Add Empty Activity Go to java -> New -> Activity -> Empty Activity Enter Activity Name: SplashActivity Hit Finish Button B) Design Splash Screen Open layout -> activity_splash.xml Cope the Background Image you want to use Paste at drawables folder Choose a file name for your image. File name must be [a-z] in lowercase 0-9 digits or underscore. Capital Letter not allowed. Now open activity_splash.xml file Enter android :background ="@drawable/bg_splash_screen" You are done Structure of activity_splash <? xml version ="1.0" encoding ="utf-8" ?> < androidx.constraintlayout.widget.ConstraintLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" xmlns: tools ="http://schemas.android.com/tools" a...

[SOLVED] Is Android Studio supported on Mac OS 10.15 (Catalina)? Android Studio Not Working on MAC

 Technically Yes! But not that all versions work the same way. While I upgraded to Android Studio to Version 4.1.2. But it did not work in OS 10.15. I deleted my previous android installations following this guide , but still nothing seemed to work. The hell bent installer seemed to get stuck in the middle. I contacted few experts who also appear clueless. A lot of time in my developers' life, I prompt to self - "Read Sid, Read!'. This was no different this time. Instead of searching for help online / offline, I started reading the Android Studio Release Note for version 4.1.2 . It clearly says ,  System Requirements  For MAC:  Mac® OS X® 10.10 (Yosemite) or higher, up to 10.14 (macOS Mojave) So, it may not work with MAC OS Catalina anyway. And it did not work as in my case. Strangely, my previous Android Version 4.0 worked. It is bit tricky to find old releases. But here is where you can find old Android Studio Archives . I downloaded Android Version 4.0, and it wor...

How do you change the launcher logo of an app in Android Studio?

We want to upload a new image to be used as Application Launcher Logo for our brand new Android App. The steps: Open existing Android Studio Project Go to Res Folder -> New -> Image Asset Make sure to keep Icon Type => Launcher Icon (Adaptive and Legacy) Select Asset Type as Image Make sure to use image dimension 475 px x 475 px Image should be in .png format and it should be named as ic_launcher.png Use online converter tools like this  Online Converter  if you get images in any other format like jpg, use that converter to convert it to png format. Beauty of Android Studio is that when you upload an image with the same name, it simply overwrites the old image. So, you need not worry much about the image file name. Besides, if you need to change the default name of an image file,  you can change it here!  Look in the application's AndroidManifest.xml file for the  <application>  tag. This application tag has an  android:icon  a...