Deepshikha Puri, the young Indian Entrepreneur heading the mobile development trade from years to successive extent, has worked with numerous clients and many tremendous brands in this industry of mobile encompassing in India and overseas maintaining promising work relationships with each of them with an impression to manage it's whole thing.

Saturday, May 12, 2018

Video Demo:


JSON means JavaScript Object Notation. Json parsing is used when our app wants to exchange data with our server. There are alots of tutorial in Json paring in android java But there are limited tutorial of json parsing in android using kotlin. So here I am showing tutorial of Jsonparsing in android Kotlin. Download source code from here


json parsing android kotlin

Add this dependency in your gradle file:

compile 'com.squareup.okhttp3:okhttp:3.8.1'

activity_main.xml:


    



MainActivity.kt:


package com.deepshikha.kotlin.jsonparsing

import android.app.ProgressDialog
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.ListView
import okhttp3.*
import org.json.JSONArray
import org.json.JSONObject
import java.io.IOException
import kotlin.collections.ArrayList

class MainActivity : AppCompatActivity() {

    lateinit var dialog:ProgressDialog
    lateinit var lv_details: ListView

    var al_details:ArrayList = ArrayList();
    val client = OkHttpClient()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        dialog= ProgressDialog.show(this@MainActivity,"Alert","Loading")
        lv_details = findViewById(R.id.lv_details) as ListView
        run("https://api.androidhive.info/contacts/")


    }

    fun run(url: String) {
        dialog.show()
        val request = Request.Builder()
                .url(url)
                .build()

        client.newCall(request).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) {
                dialog.dismiss()

            }

            override fun onResponse(call: Call, response: Response) {
                var str_response = response.body()!!.string()
                val json_contact:JSONObject = JSONObject(str_response)

                var jsonarray_contacts:JSONArray= json_contact.getJSONArray("contacts")

                var i:Int = 0
                var size:Int = jsonarray_contacts.length()

                al_details= ArrayList();

                for (i in 0.. size-1) {
                    var json_objectdetail:JSONObject=jsonarray_contacts.getJSONObject(i)


                    var model:Model= Model();
                    model.id=json_objectdetail.getString("id")
                    model.name=json_objectdetail.getString("name")
                    model.email=json_objectdetail.getString("email")
                    model.address=json_objectdetail.getString("address")
                    model.gender=json_objectdetail.getString("gender")

                    al_details.add(model)


                }

                runOnUiThread {
                    //stuff that updates ui
                    val obj_adapter : CustomAdapter
                    obj_adapter = CustomAdapter(applicationContext,al_details)
                    lv_details.adapter=obj_adapter
                }

                dialog.dismiss()

            }

        })

    }


}

adapter_layout.xml:


    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/ll_main"
    android:background="#e4e2e2"
    android:padding="5dp"
    android:orientation="vertical">

            android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv_name"
        android:textSize="15dp"
        android:layout_margin="5dp"
        android:textColor="#000000"/>

            android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv_email"
        android:layout_margin="5dp"
        android:textSize="15dp"
        android:textColor="#000000"/>

            android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv_address"
        android:layout_margin="5dp"
        android:textSize="15dp"
        android:textColor="#000000"/>




CustomAdapter.kt:

package com.deepshikha.kotlin.jsonparsing

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView

/**
 * Created by deepshikha on 1/11/17.
 */

class CustomAdapter(context: Context,al_details:ArrayList) : BaseAdapter(){

    private val mInflator: LayoutInflater
    private val al_details:ArrayList

    init {
        this.mInflator = LayoutInflater.from(context)
        this.al_details=al_details
    }

    override fun getCount(): Int {
        return al_details.size
    }

    override fun getItem(position: Int): Any {
        return al_details.get(position)
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View? {
        val view: View?
        val vh: ListRowHolder
        if (convertView == null) {
            view = this.mInflator.inflate(R.layout.adapter_layout, parent, false)
            vh = ListRowHolder(view)
            view.tag = vh
        } else {
            view = convertView
            vh = view.tag as ListRowHolder
        }

        vh.tv_name.text = al_details.get(position).name
        vh.tv_email.text = al_details.get(position).email
        vh.tv_address.text = al_details.get(position).address
        if (position%2==0) {
            vh.ll_main.setBackgroundColor(Color.parseColor("#e4e2e2"))
        }else{
            vh.ll_main.setBackgroundColor(Color.parseColor("#FFFFFF"))

        }
        return view
    }
}

private class ListRowHolder(row: View?) {
    public val tv_name: TextView
    public val tv_email: TextView
    public val tv_address: TextView
    public val ll_main: LinearLayout

    init {
        this.tv_name = row?.findViewById(R.id.tv_name) as TextView
        this.tv_email = row?.findViewById(R.id.tv_email) as TextView
        this.tv_address = row?.findViewById(R.id.tv_address) as TextView
        this.ll_main = row?.findViewById(R.id.ll_main) as LinearLayout
    }


} 

Model.kt:


package com.deepshikha.kotlin.jsonparsing

/**
 * Created by deepshikha on 31/10/17.
 */
public class Model{
    lateinit var id:String
    lateinit var name:String
    lateinit var email:String
    lateinit var address:String
    lateinit var gender:String

    constructor(id: String,name:String,email:String,address:String,gender:String) {
        this.id = id
        this.name = name
        this.email = email
        this.address = address
        this.gender = gender
    }

    constructor()


}

Saturday, April 28, 2018

change theme programmatically android

Themes and Styles on Android allow us to separate the details of our app design from the UI structure and behavior, Similar to Stylesheets in web design. Download source code from here

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/rl_header"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/colorPrimary"></RelativeLayout>

    <Button
        android:id="@+id/btn_red"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:text="Red" />

    <Button
        android:id="@+id/btn_yellow"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:text="Yellow" />


    <Button
        android:id="@+id/btn_green"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:text="Green" />

    <Button
        android:id="@+id/btn_purple"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:text="Purple" />

</LinearLayout>


MainActivity.kt:


package changetheme.deepshikha.com.changetheme

import android.graphics.Color
import android.os.Build
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity(), View.OnClickListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        listener()
        init()
    }

    private fun init() {

    }

    private fun listener() {
        btn_red.setOnClickListener(this)
        btn_yellow.setOnClickListener(this)
        btn_green.setOnClickListener(this)
        btn_purple.setOnClickListener(this)
    }


    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.btn_red -> {
                fn_changethemecolor(resources.getColor(R.color.theme_red), resources.getColor(R.color.red))
            }

            R.id.btn_yellow -> {
                fn_changethemecolor(resources.getColor(R.color.theme_yellow), resources.getColor(R.color.yellow))
            }

            R.id.btn_green -> {
                fn_changethemecolor(resources.getColor(R.color.theme_green), resources.getColor(R.color.green))
            }

            R.id.btn_purple -> {
                fn_changethemecolor(resources.getColor(R.color.theme_purple), resources.getColor(R.color.purple))
            }
        }
    }


    /**
     * Method for change theme color
     */
    fun fn_changethemecolor(color: Int, header_color: Int) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            val window = window
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
            window.statusBarColor = color

        }
        rl_header.setBackgroundColor(header_color)

    }
}


Saturday, April 21, 2018

create custom toast class android

A toast is used to display simple feedback about an operation in popup and automatically fade out after timeout. In this tutorial I am create a custom toast by using custom layout. Download source code from here:

activity_main:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp">


    <Button
        android:id="@+id/btn_refresh"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="Refresh Toast" />

    <Button
        android:id="@+id/btn_error2"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:text="Info" />

    <Button
        android:id="@+id/btn_network"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:text="Network Toast" />

    <Button
        android:id="@+id/btn_error"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:text="Error Toast" />

</LinearLayout>

custom_toast.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_toast_container"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="8dp"
    android:background="#DAAA">
    <ImageView android:src="@drawable/ic_launcher_background"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/iv_image"
        android:layout_marginRight="8dp"
        />
    <TextView android:id="@+id/tv_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#FFF"
        />
</LinearLayout>


MainActivity.kt:
package com.deepshikha.customtoast

import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.custom_toast.view.*

class MainActivity : AppCompatActivity(), View.OnClickListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        listener()
    }

    private fun listener() {
        btn_refresh.setOnClickListener(this)
        btn_error2.setOnClickListener(this)
        btn_network.setOnClickListener(this)
        btn_error.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.btn_error2 -> {
                var toast: Toast = Toast(this)
                toast.createToast(this, "Dummy data is benign information", Gravity.BOTTOM, Toast.LENGTH_SHORT, "#eab04c", R.drawable.ic_info_black_24dp)
            }

            R.id.btn_refresh -> {

                var toast: Toast = Toast(this)
                toast.createToast(this, "Data has been Refreshed", Gravity.BOTTOM, Toast.LENGTH_SHORT, "#2ba622", R.drawable.ic_autorenew_black_24dp)

            }

            R.id.btn_network -> {

                var toast: Toast = Toast(this)
                toast.createToast(this, "Check your Internet connection", Gravity.BOTTOM, Toast.LENGTH_SHORT, "#7c5ffa", R.drawable.ic_network_check_black_24dp)

            }

            R.id.btn_error -> {
                var toast: Toast = Toast(this)
                toast.createToast(this, "Error: Server not found", Gravity.BOTTOM, Toast.LENGTH_SHORT, "#ec1e1e", R.drawable.ic_error_outline_black_24dp)
            }
        }
    }

    fun Toast.createToast(context: Context, message: String, gravity: Int, duration: Int, backgroucolor: String, imagebackgroud: Int) {
        val inflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        /*first parameter is the layout you made
        second parameter is the root view in that xml
         */
        val layout = inflater.inflate(R.layout.custom_toast, (context as Activity).findViewById(R.id.custom_toast_container))

        layout.findViewById(R.id.tv_message).text = message
        layout.setBackgroundColor(Color.parseColor(backgroucolor))
        layout.findViewById(R.id.iv_image).iv_image.setImageResource(imagebackgroud)
        setGravity(gravity, 0, 100)
        setDuration(Toast.LENGTH_LONG);

        setView(layout);
        show()
    }

}

Saturday, March 17, 2018

android parcelable tutorial

In Android Parcelable interface is used to transfer the Arraylist or Object from one Activity to another activity. Parcelable is faster then serialization. Download the source code from below.

activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:context="com.deepshikha.parcelable.MainActivity">

    <ListView
        android:id="@+id/lv_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteX="8dp" />
</android.support.constraint.ConstraintLayout>


adapter_category.xml:



<android.support.constraint.ConstraintLayout 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"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageView
        android:id="@+id/iv_image"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.029"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.02"
        tools:ignore="VectorDrawableCompat" />

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="200dp"
        android:layout_height="30dp"
        android:layout_marginEnd="68dp"
        android:layout_marginLeft="10dp"
        android:ellipsize="end"
        android:maxLines="1"
        android:paddingLeft="20dp"
        android:paddingRight="10dp"
        android:singleLine="true"
        android:text="TextView"
        android:textColor="#000000"
        android:textSize="15sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/iv_image"
        app:layout_constraintTop_toTopOf="@+id/iv_image" />

    <TextView
        android:id="@+id/tv_des"
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:ellipsize="end"
        android:maxLines="2"
        android:text="TextView"
        android:textColor="#000000"
        android:textSize="12sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.36"
        app:layout_constraintLeft_toRightOf="@+id/iv_image"
        app:layout_constraintTop_toBottomOf="@+id/tv_name" />
</android.support.constraint.ConstraintLayout>
MainActivity.java:
package com.deepshikha.parcelable;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.deepshikha.parcelable.Model.Category;

import java.lang.reflect.Array;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    ArrayList al_category = new ArrayList<>();
    ListView lv_category;
    Button btn_next;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        lv_category = (ListView) findViewById(R.id.lv_category);

        al_category.add(new Category("C", "C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations.", R.drawable.ic_clogo));
        al_category.add(new Category("Css", "Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation of a document written in a markup language", R.drawable.ic_css));
        al_category.add(new Category("Java", "Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible.", R.drawable.ic_java));
        al_category.add(new Category("PHP", "PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language.", R.drawable.ic_php));
        al_category.add(new Category("JavaScript", "JavaScript, often abbreviated as JS, is a high-level, interpreted programming language. It is a language which is also characterized as dynamic, weakly typed, prototype-based and multi-paradigm.", R.drawable.ic_javascript));


        CategoryAdapter categoryAdapter = new CategoryAdapter(getApplicationContext(), al_category);
        lv_category.setAdapter(categoryAdapter);

        lv_category.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView parent, View view, int position, long id) {

                Intent intent = new Intent(getApplicationContext(), CategoryDetails.class);
//                intent.putParcelableArrayListExtra("value",al_category);
                intent.putExtra("value", al_category.get(position));
                startActivity(intent);

            }
        });
    }

    public class CategoryAdapter extends ArrayAdapter {

        public CategoryAdapter(Context context, ArrayList users) {
            super(context, 0, users);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // Get the data item for this position
            Category category = getItem(position);
            // Check if an existing view is being reused, otherwise inflate the view
            if (convertView == null) {
                convertView = LayoutInflater.from(getContext()).inflate(R.layout.adapter_category, parent, false);
            }
            // Lookup view for data population
            TextView tvName = (TextView) convertView.findViewById(R.id.tv_name);
            TextView tv_des = (TextView) convertView.findViewById(R.id.tv_des);
            ImageView iv_image = (ImageView)convertView.findViewById(R.id.iv_image);

            // Populate the data into the template view using the data object
            tvName.setText(category.getStr_name());
            iv_image.setImageResource(category.getInt_image());
            tv_des.setText(category.getStr_des());

            // Return the completed view to render on screen
            return convertView;
        }
    }
}

Category.java:
package com.deepshikha.parcelable.Model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by deepshikha on 22/2/18.
 */

public class Category implements Parcelable {
    String str_name, str_des;
    int int_image;

    public Category(String str_name, String str_des, int int_image) {
        this.str_name = str_name;
        this.str_des = str_des;
        this.int_image = int_image;
    }

    public String getStr_name() {
        return str_name;
    }

    public void setStr_name(String str_name) {
        this.str_name = str_name;
    }

    public String getStr_des() {
        return str_des;
    }

    public void setStr_des(String str_des) {
        this.str_des = str_des;
    }

    public int getInt_image() {
        return int_image;
    }

    public void setInt_image(int int_image) {
        this.int_image = int_image;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.str_name);
        dest.writeString(this.str_des);
        dest.writeInt(this.int_image);
    }

    public Category() {
    }

    protected Category(Parcel in) {
        this.str_name = in.readString();
        this.str_des = in.readString();
        this.int_image = in.readInt();
    }

    public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
        @Override
        public Category createFromParcel(Parcel source) {
            return new Category(source);
        }

        @Override
        public Category[] newArray(int size) {
            return new Category[size];
        }
    };
}

activity_category_details.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.deepshikha.parcelable.CategoryDetails">


    <ImageView
        android:id="@+id/iv_image"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:src="@drawable/ic_clogo"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.084" />

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="TextView"
        android:textColor="#000000"
        android:textSize="20sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.028"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/iv_image"
        app:layout_constraintVertical_bias="0.004" />

    <TextView
        android:id="@+id/tv_des"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:text="TextView"
        android:textColor="#000000"
        android:textSize="12sp"
        app:layout_constraintHorizontal_bias="0.108"
        app:layout_constraintLeft_toLeftOf="@+id/tv_name"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tv_name" />
</android.support.constraint.ConstraintLayout>

CategoryDetails.java:
package com.deepshikha.parcelable;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.deepshikha.parcelable.Model.Category;

import java.lang.reflect.Array;
import java.util.ArrayList;

public class CategoryDetails extends AppCompatActivity {

    Category category;
    ImageView iv_image;
    TextView tv_name, tv_des;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_category_details);
        category = getIntent().getParcelableExtra("value");

        init();

    }

    private void init() {
        iv_image = (ImageView) findViewById(R.id.iv_image);
        tv_des = (TextView) findViewById(R.id.tv_des);
        tv_name = (TextView) findViewById(R.id.tv_name);

        tv_name.setText(category.getStr_name());
        tv_des.setText(category.getStr_des());
        iv_image.setImageResource(category.getInt_image());
    }
}


DOWNLOAD SOURCE CODE FROM HERE.


Saturday, March 3, 2018

Video Demo:




TabLayout provides a horizontal layout to display tabs. We can show the number of layout in single screen. In this tutorial, I am using the two fragments to shows the tab data. DOWNLOAD SOURCE CODE FROM BELOW:

tablayout in android kotlin
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <android.support.design.widget.TabLayout
        android:id="@+id/tb_fragments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#17d236"
        app:tabIndicatorColor="#000000"
        app:tabSelectedTextColor="#ffffff"
        app:tabTextColor="#000000">

    </android.support.design.widget.TabLayout>

    <FrameLayout
        android:id="@+id/fl_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </FrameLayout>

</LinearLayout>
MainActivity.kt:
package com.deepshikha.tablayoutkotlin

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.design.widget.TabLayout
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() , TabLayout.OnTabSelectedListener {
    lateinit var homefragment:HomeFragment
    lateinit var contactfragment:ContactFragment

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        init()
    }

    private fun init() {
        supportActionBar!!.hide()

        homefragment= HomeFragment()
        contactfragment= ContactFragment()

        val firstTab = tb_fragments.newTab()
        firstTab.setText("Home")
        firstTab.setIcon(R.drawable.home)
        tb_fragments.addTab(firstTab)

        val secondTab = tb_fragments.newTab()
        secondTab.setText("Email")
        secondTab.setIcon(R.drawable.email)
        tb_fragments.addTab(secondTab)

        tb_fragments.setOnTabSelectedListener(this)

        supportFragmentManager
                .beginTransaction()
                .add(R.id.fl_container,homefragment)
                .commit()
    }

    override fun onTabReselected(tab: TabLayout.Tab?) {
    }

    override fun onTabUnselected(tab: TabLayout.Tab?) {

    }

    override fun onTabSelected(tab: TabLayout.Tab?) {
        when(tab!!.position){
            0-> {
                supportFragmentManager
                        .beginTransaction()
                        .replace(R.id.fl_container, homefragment)
                        .commit()
            }

            1-> {
                supportFragmentManager
                        .beginTransaction()
                        .replace(R.id.fl_container, contactfragment)
                        .commit()
            }

        }
    }

}

fragment_home.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    
    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webview"></WebView>

</LinearLayout>


HomeFragment.kt:
package com.deepshikha.tablayoutkotlin

import android.app.ProgressDialog
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebView
import android.webkit.WebViewClient

/**
 * Created by deepshikha on 2/2/18.
 */
public class HomeFragment : Fragment() {
    lateinit var view12: View
    var mywebview: WebView? = null
    lateinit var progressdialog: ProgressDialog
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

        view12 = inflater!!.inflate(R.layout.fragment_home, container, false)
        init()
        return view12
    }

    private fun init() {

        progressdialog = ProgressDialog.show(activity, "Please Wait", "Loading");
        mywebview = view12.findViewById(R.id.webview)
        mywebview!!.webViewClient = object : WebViewClient() {
            override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
                view?.loadUrl(url)
                return true
            }

            override fun onPageFinished(view: WebView?, url: String?) {
                super.onPageFinished(view, url)
                progressdialog.dismiss()
            }
        }
        mywebview!!.loadUrl("http://deepshikhapuri.blogspot.in/")


//        webview = view12.findViewById(R.id.webview) as WebView
//        val webSettings = webview.settings
//        webSettings.javaScriptEnabled = true
//
//        webview.loadUrl("http://deepshikhapuri.blogspot.in/")
//        webview.setweb

    }
}
fragment_contact.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical">

    <TextView
        android:textColor="#000000"
        android:text="deepshikhapuri.here@gmail.com"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"/>

</RelativeLayout>

ContactFragment.kt:
package com.deepshikha.tablayoutkotlin

import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

/**
 * Created by deepshikha on 2/2/18.
 */
public class ContactFragment:Fragment(){
    lateinit var view12: View

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
           view12 = inflater!!.inflate(R.layout.fragment_contact, container, false)
        return view12
    }
}

DOWNLOAD SOURCE CODE FROM HERE


Sunday, February 18, 2018

Video Demo:


TabLayout provides a horizontal layout to display tabs. We can show the number of layout in single screen. In this tutorial I am using the two fragments to shows the tab data. DOWNLOAD SOURCE CODE FROM BELOW:

android material design tabs

activity_main.xml:;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <android.support.design.widget.TabLayout
        android:id="@+id/tb_fragments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#f96239"
        app:tabIndicatorColor="#000000"
        app:tabSelectedTextColor="#ffffff"
        app:tabTextColor="#000000">

    </android.support.design.widget.TabLayout>

    <FrameLayout
        android:id="@+id/fl_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</LinearLayout>
MainActivity.javapackage com.deepshikha.tablayout;
package com.deepshikha.tablayout;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.widget.FrameLayout;

public class MainActivity extends AppCompatActivity {
    TabLayout tb_fragments;
    FrameLayout fl_main;
    HomeFragment homeFragment;
    ContactFragment contactFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
        init();
    }

    private void init(){
        tb_fragments = (TabLayout)findViewById(R.id.tb_fragments);
        fl_main = (FrameLayout) findViewById(R.id.fl_main);

        TabLayout.Tab firstTab = tb_fragments.newTab();
        firstTab.setText("Home");
        firstTab.setIcon(R.drawable.home);
        tb_fragments.addTab(firstTab);

        TabLayout.Tab secondTab = tb_fragments.newTab();
        secondTab.setText("Email");
        secondTab.setIcon(R.drawable.email);
        tb_fragments.addTab(secondTab);

        homeFragment = new HomeFragment();
        contactFragment = new ContactFragment();

        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.fl_main, homeFragment);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.commit();

        tb_fragments.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                Fragment fragment = null;
                switch (tab.getPosition()) {
                    case 0:
                        fragment = homeFragment;
                        break;
                    case 1:
                        fragment = contactFragment;
                        break;

                }
                FragmentManager fm = getSupportFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();
                ft.replace(R.id.fl_main, fragment);
                ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                ft.commit();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {


            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });


    }
}
fragment_home.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webview"></WebView>


</RelativeLayout>
HomeFragment.java:
package com.deepshikha.tablayout;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;

/**
 * Created by deepshikha on 2/2/18.
 */

public class HomeFragment extends Fragment {

    WebView webview;
    View view;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

        if (view==null) {
            view = inflater.inflate(R.layout.fragment_home, container, false);
            init();
        }
        return view;

    }

    private void init(){
        webview=(WebView)view.findViewById(R.id.webview);
        startWebView("http://deepshikhapuri.blogspot.in/");
    }

    private void startWebView(String url) {

        WebSettings settings = webview.getSettings();

        settings.setJavaScriptEnabled(true);
        webview.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);

        webview.getSettings().setBuiltInZoomControls(true);
        webview.getSettings().setUseWideViewPort(true);
        webview.getSettings().setLoadWithOverviewMode(true);

        final  ProgressDialog progressDialog = new ProgressDialog(getActivity());
        progressDialog.setMessage("Loading...");
        progressDialog.setCancelable(false);
        progressDialog.show();

        webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
            }

            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Log.e("ERRROr",description);
                Toast.makeText(getActivity(), "Error:" + description, Toast.LENGTH_SHORT).show();

            }
        });
        webview.loadUrl(url);
    }

}
fragment_contactus.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:textColor="#000000"
        android:gravity="center"
        android:padding="10dp"
        android:layout_centerInParent="true"
        android:text="deepshikhapuri.here@gmail.com"/>

</RelativeLayout>
ContactFragment.java:
package com.deepshikha.tablayout;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by deepshikha on 2/2/18.
 */

public class ContactFragment extends Fragment {

    View view;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.fragment_contactus,container,false);
        return view;

    }
}

DOWNLOAD SOURCE CODE FROM HERE

Sunday, February 11, 2018

Video Demo:


In this tutorial, I am creating a demo of expandable listview with search bar. Expandable listview is used to show the data according to particular category. You can expand or collapse the data of particular group. To search the data I am using the TextWatcher. DOWNLOAD SOURCE CODE FROM BELOW
android expandablelistview search filter example

activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/rl_header"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:background="#067b16"
        android:gravity="center"
        android:textColor="#ffffff">
    </TextView>
    <RelativeLayout
        android:id="@+id/rl_search"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_below="@+id/rl_header"
        android:background="#EFEFF4">
        <EditText
            android:id="@+id/et_search"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_centerInParent="true"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/drawable_search"
            android:drawableLeft="@android:drawable/ic_menu_search"
            android:drawablePadding="10dp"
            android:hint="Search"
            android:paddingLeft="10dp"
            android:paddingRight="10dp" />
    </RelativeLayout>
    <ExpandableListView
        android:id="@+id/ev_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/rl_search">
    </ExpandableListView>
</RelativeLayout>
MainActivity.java:
 package com.deepshikha.expandablelistviewsearch;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by deepshikha Puri on 16/1/18.
 */

public class MainActivity extends AppCompatActivity {
    ExpandableListView ev_list;
    List> lv_country = new ArrayList<>();
    CustomAdapter customAdapter;
    EditText et_search;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
        init();

    }

    private void init() {
        ev_list = (ExpandableListView) findViewById(R.id.ev_list);
        et_search = (EditText) findViewById(R.id.et_search);

        fn_arraylist();
        customAdapter = new CustomAdapter(lv_country, getApplicationContext());
        ev_list.setAdapter(customAdapter);

        ev_list.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                return true; // This way the expander cannot be collapsed
            }
        });

        for (int i = 0; i < customAdapter.getGroupCount(); i++) {
            ev_list.expandGroup(i);
        }


        et_search.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {

                if (et_search.getText().toString().length() == 0) {
                    customAdapter = new CustomAdapter(lv_country, getApplicationContext());
                    ev_list.setAdapter(customAdapter);

                    for (int i = 0; i < customAdapter.getGroupCount(); i++) {
                        ev_list.expandGroup(i);
                    }
                } else {

                    List> lv_search = new ArrayList<>();

                    for (int i = 0; i < lv_country.size(); i++) {
                        List> lv_searchstate = new ArrayList<>();

                        List> lv_state = (List>) lv_country.get(i).get("State");
                        for (int j = 0; j < lv_state.size(); j++) {
                            if (lv_state.get(j).get("Name").toString().toLowerCase().contains(et_search.getText().toString())) {
                                lv_searchstate.add(lv_state.get(j));
                            }
                        }

                        if (lv_searchstate.size() != 0) {
                            HashMap hashMap_search = new HashMap<>();
                            hashMap_search.put("Name", lv_country.get(i).get("Name").toString());
                            hashMap_search.put("State", lv_searchstate);

                            lv_search.add(hashMap_search);
                        }
                    }


                    customAdapter = new CustomAdapter(lv_search, getApplicationContext());
                    ev_list.setAdapter(customAdapter);

                    for (int i = 0; i < customAdapter.getGroupCount(); i++) {
                        ev_list.expandGroup(i);
                    }


                }

            }
        });


    }

    private void fn_arraylist() {
        /*Afghanistan*/
        HashMap hashMap_country = new HashMap<>();
        hashMap_country.put("Name", "Afghanistan");

        List> lv_state = new ArrayList<>();
        HashMap hashMap_state = new HashMap<>();


        hashMap_state.put("Name", "Kabul");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Kandahar");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Herat");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Mazar-i-Sharif");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Kunduz");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Jalalabad");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Lashkar Gah");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Taluqan");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Puli Khumri");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Khost");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Ghazni");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Sheberghan");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Sari Pul ");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_country.put("State", lv_state);

        lv_country.add(hashMap_country);

        /*India*/
        hashMap_country = new HashMap<>();
        hashMap_country.put("Name", "India");

        lv_state = new ArrayList<>();
        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Arunachal Pradesh");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Assam");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Bihar");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Chandigarh");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Chhattisgarh");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Goa");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Gujarat");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Haryana");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Himachal Pradesh");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Jammu and Kashmir");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Jharkhand");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Maharashtra");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Odisha");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Punjab");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Rajasthan");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Sikkim");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Uttarakhand");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "West Bengal");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();

        hashMap_country.put("State", lv_state);
        lv_country.add(hashMap_country);

        /*America*/
        hashMap_country = new HashMap<>();
        hashMap_country.put("Name", "America");

        lv_state = new ArrayList<>();
        hashMap_state = new HashMap<>();

        hashMap_state.put("Name", "California");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Texas");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Hawaii");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Florida");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Alabama");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Alaska");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Pennsylvania");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "New Jersey");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Minnesota");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Georgia");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Colorado");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "North Carolina");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "Indiana");
        lv_state.add(hashMap_state);

        hashMap_state = new HashMap<>();
        hashMap_state.put("Name", "New Mexico");
        lv_state.add(hashMap_state);

        hashMap_country.put("State", lv_state);
        lv_country.add(hashMap_country);

    }

}

adapter_child.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv_child"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:text="Child"
        android:textColor="#000000"
        android:textSize="15dp" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentBottom="true"
        android:background="#000000">

    </View>

</RelativeLayout>
 adapter_header.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv_headername"
        android:layout_width="match_parent"
        android:textSize="15dp"
        android:layout_height="match_parent"
        android:background="#067b16"
        android:gravity="center_vertical"
        android:padding="10dp"
        android:text="Header"
        android:textColor="#FFFFFF" />

</LinearLayout>

CustomAdapter.java:

package com.deepshikha.expandablelistviewsearch;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import java.util.HashMap;
import java.util.List;

/**
 * Created by deepshikha Puri on 16/1/18.
 */

public class CustomAdapter extends BaseExpandableListAdapter {
    List> lv_data;
    Context context;

    public CustomAdapter(List> lv_data, Context context) {
        this.lv_data = lv_data;
        this.context = context;
    }

    @Override
    public int getGroupCount() {
        return lv_data.size();
    }

    @Override
    public int getChildrenCount(int i) {

        List> lv_state = (List>) lv_data.get(i).get("State");
        return lv_state.size();
    }

    @Override
    public Object getGroup(int i) {
        return lv_data.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {


        List> lv_state = (List>) lv_data.get(i).get("State");
        return lv_state.get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int i, boolean b, View convertView, ViewGroup viewGroup) {

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this.context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.adapter_header, null);
        }

        TextView tv_header = (TextView) convertView.findViewById(R.id.tv_headername);
        tv_header.setText(lv_data.get(i).get("Name").toString());
        return convertView;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View convertView, ViewGroup viewGroup) {

        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.adapter_child, null);
        }

        TextView tv_chid = (TextView) convertView.findViewById(R.id.tv_child);

        List> lv_state = (List>) lv_data.get(i).get("State");
        tv_chid.setText(lv_state.get(i1).get("Name").toString());

        return convertView;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }
}

DOWNLOAD SOURCE CODE FROM HERE