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.

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