Tuesday 8 October 2019

Android MVP template | Android MVP Plugin

Hello Friends,
              Today I am sharing the android MVP template which make the development
Faster. This is an android studio template inspired by android view-model template.

When we follow Android MVP architecture in any project, for each module or feature
we need to create an Activity/Fragment,  a Presenter and a Contract class and also
a layout file corresponding to them. This is really an time taking process.

So Taking advantage of Android Studio template I created  a MVP template
which creates all this file at the start.

Getting Started

1.  Download the MVPActivity Teamplate ,which you found at the bottom of this blog.
2.  For WINDOWJust copy directory MVPActivity
                     to  $ANDROID_STUDIO_FOLDER$\plugins\android\lib\templates\activities\
3. For  Mac,  Just copy directory MVPActivity
                     to $ANDROID_STUDIO_FOLDER$/Contents/plugins/android/lib/templates/activities/



4. Below are the few common files,
       A. template.xml  – This will contain information about the template
             name, minSdkVersion, etc    


     B. recipe.xml.ftl - This will contain instructions explaining how to
            create the template, including what variables to ask the user for and
            what should be done with those variables.
    C. globals.xml.ftl – This defines global variables

    D. root/ folder – this will contain the template code.





Download code from here
Hope this will helps some one...
Enjoy Coding........... :)

Monday 7 October 2019

Kotlin Android - RecyclerView Example

Hello Friends,
          Today I am sharing the demo of RecyclerView in Kotlin.
A RecyclerView is essentially a ViewGroup of containers called ViewHolders which
populate a particular item.



So lets first familiar with RecyclerView and What RecyclerView requires:
1. It requires a set of data objects to work with
2. An xml file of the individual view item
3. An adapter to bind that data to the views shown in the ViewHolders
4. ViewHolder to populate the UI from the xml item file


Getting Started

Download code from here
Hope this will helps someone.
Enjoy coding.... :)

Saturday 5 October 2019

Kotlin Android – AlertDialog – Example

Hello Friends,
                Here is the demo Alert Dialog in Kotlin. Android AlertDialog class
                is used to display a dialog box to user with positive and negative buttons.
It Appears on top of the activity layout. You may not physically access any other
UI components of activity. It will be run on UI thread.






To Create an AlertDialog, step by step process is :

1. Create an AlertDialog Builder using the activity’s context.
2. Set message content using the builder.
3. Set Positive Button Text and Action to be taken when the button is clicked using the builder.
4. Set Negative Button Text and Action to be taken when the button is clicked using the builder.
5. Create AlertDialog from the builder.
6. You may set the title to the AlertDialog box using setTitle() method.

1. MainActivity.kt
package com.android.developer.soulutions.myapplication

import android.content.DialogInterface
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.app.AlertDialog
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        btnShowAlert.setOnClickListener {
            // build alert dialog
            val dialogBuilder = AlertDialog.Builder(this)

            // set message of alert dialog
            dialogBuilder.setMessage("Do you want to close this  ?")
                    // if the dialog is cancelable
                    .setCancelable(false)
                    // positive button text and action
                    .setPositiveButton("OK", DialogInterface.OnClickListener { dialog, id ->
                        finish()
                    })
                    // negative button text and action
                    .setNegativeButton("Cancel", DialogInterface.OnClickListener { dialog, id ->
                        dialog.cancel()
                    })

            // create dialog box
            val alert = dialogBuilder.create()
            // set title for alert dialog box
            alert.setTitle("AlertDialogExample")
            // show alert dialog
            alert.show()
        };
    }
}
 

Download the code from here

Hope this will helps someone.
Enjoy Coding................... :)


 

Copyright @ 2013 Android Developers Blog.