Open top menu


In this tutorial we will implement Google Map with Google Map API in android. so,explain Step by Step.

Step .1:- Frist ,you can register you android project on  Google Developer Console get the api key.the api key get via SHA-1 fingerprint.

Step 2:-Open Google Developer Console link.

Step 3:- Add Map Key in Manifest Class.
..................................................................................................................................................................

<meta-data  
android:name="com.google.android.geo.API_KEY"  
android:value="Paste_your_key"/>

.................................................................................................................................................................


Step 3:-  Google map need some Permission so you have to add in manifest ,

AndroidManifast.xml
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"    
package="com.example.sarvesh.testproject">

<application        
android:allowBackup="true"        
android:icon="@mipmap/ic_launcher"        
android:label="@string/app_name"        
android:supportsRtl="true"        
android:theme="@style/AppTheme">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="myapp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>  
      
<uses-feature            
android:glEsVersion="0x00020000"            
android:required="true"/>

        
<meta-data            
android:name="com.google.android.geo.API_KEY"            
android:value="Api_key"/>   
</application>
</manifest>


..................................................................................................................................................................


Step 4:- Then google maps are implement MapFragment which is subclass of  Fragment. open your activity_main and add this fragment in Layout.

activity_main.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:background="@drawable/register_cover"    
android:orientation="vertical"    
android:padding="10dp">

    
<fragment        
android:name="com.google.android.gms.maps.MapFragment"        
android:id="@+id/map"        
android:layout_width="match_parent"        
android:layout_height="match_parent"/>

</LinearLayout>
...................................................................................................................................................................



Step 5:-  then, implement some code in MainActivity.java class.

...................................................................................................................................................................
package com.example.sarvesh.testproject;

import android.app.ActionBar;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.SparseBooleanArray;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import java.util.ArrayList;

public class MainActivity extends Activity {

    // Google Map    private GoogleMap googleMap;
    double latitude = 20.5937;
    double longitude =78.9629;


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

        try {
            // Loading map            initilizeMap();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**     * function to load map. If map is not created it will create it for you     */   
 private void initilizeMap() {
        
if (googleMap == null) {
          
  googleMap = ((MapFragment) getFragmentManager().findFragmentById( R.id.map)).getMap();
  MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Androidbeginnerpoint");
  googleMap.addMarker(marker);

            
// check if map is created successfully or not            
if (googleMap == null) {
   Toast.makeText(getApplicationContext(),"Sorry! unable to create maps", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }
    @Override    protected void onResume() {
        super.onResume();
        initilizeMap();
    }
}

.................................................................................................................................................................


 try this tutorial....







Read more


 In this tutorial Implement multiple Choice Custom Spinner in android. explain Briefly..

Step1 create gradient xml inside res/drawable folder..

text_cover.xml
...................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" 
android:padding="7dp">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="3dp"
android:bottomLeftRadius="3dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp"/>

<stroke android:width="2dip" 
android:color="#dce0e2" />  
</shape>

...................................................................................................................................................................

Step 2 Create activity_main xml inside res/layout folder..
activity_main.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:background="@drawable/register_cover"    
android:orientation="vertical"   
android:padding="10dp">


<ImageView        
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:id="@+id/imageView"        
android:layout_gravity="center"        
android:src="@drawable/my_heder_img"/>
<LinearLayout        
android:layout_width="match_parent"        
android:layout_height="wrap_content"        
android:layout_margin="4dp"        
android:orientation="horizontal"        
android:weightSum="2">
    
</LinearLayout>

<LinearLayout        
android:layout_width="match_parent"        
android:layout_height="wrap_content"        
android:layout_margin="4dp"        
android:gravity="center_horizontal"        
android:orientation="horizontal"        
android:weightSum="2">
        
<TextView            

android:layout_width="150dp"           
android:layout_height="48dp"
android:layout_weight="1"            
android:gravity="center_vertical"            
android:text="Select Item" />

        
<LinearLayout            
android:layout_width="match_parent"            
android:layout_height="wrap_content"            
android:layout_margin="4dp"            
android:layout_weight="1"            
android:gravity="center_horizontal"            
android:orientation="vertical"            
android:weightSum="2">

            
<TextView                
android:id="@+id/textView44"                
android:layout_width="fill_parent"                
android:layout_height="50dp"                
android:text=""                
android:background="@drawable/edit_text_gradient"                
android:drawableRight="@drawable/short_dwon"                
android:gravity="center_vertical"                
android:paddingLeft="18dp"                
android:textSize="18dp" />
            
<LinearLayout                
android:orientation="vertical"                
android:layout_width="match_parent"                
android:layout_height="match_parent"                
android:id="@+id/layout"                
android:background="@drawable/edit_text_gradient"                
android:visibility="invisible"                 >
            
<ListView                
android:id="@+id/spinAddGuest"                
android:layout_width="match_parent"               
android:layout_height="250dp"                
android:visibility="invisible" />

            
<Button                
android:layout_width="match_parent"                
android:layout_height="wrap_content"                
android:text="Ok"               
 android:id="@+id/button"               
 android:visibility="invisible"                
android:layout_margin="7dp"                
android:background="@drawable/register_cover"                
android:layout_gravity="center_horizontal" />
            
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

...................................................................................................................................................................

Step 3 Create MainActivity inside srcfolder.
MainActivity.Java.
...................................................................................................................................................................
package com.example.sarvesh.testproject;

import android.app.ActionBar;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.SparseBooleanArray;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends Activity {
    ArrayList<String> item_array;
    String specialAssistence;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActionBar();

        setContentView(R.layout.activity_main);
        item_array = new ArrayList<String>();
        for (int i = 0; i < 10; i++) {
            item_array.add("Item" + i);
        }

        final ListView spinCount = (ListView) findViewById(R.id.spinAddGuest);
        final TextView text = (TextView) findViewById(R.id.textView44);
        final Button okbtn = (Button) findViewById(R.id.button);
        final LinearLayout layout = (LinearLayout) findViewById(R.id.layout);

        text.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
                spinCount.setVisibility(View.VISIBLE);
                okbtn.setVisibility(View.VISIBLE);
                layout.setVisibility(View.VISIBLE);
            }
        });
        ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_multiple_choice, item_array);
        spinCount.setAdapter(spinnerArrayAdapter);
        spinCount.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        spinCount.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            }
        });
        okbtn.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
                SparseBooleanArray positions = spinCount.getCheckedItemPositions();
                int j = 0;
                for (int k = 0; k < item_array.size(); k++) {
                    if (positions.get(k)) {
                        String str = item_array.get(k);


                            specialAssistence = specialAssistence + ",\t" + str;

                    }
                }
                if(!specialAssistence.isEmpty()) {
                    text.setText(specialAssistence.substring(5).trim());
                }
                spinCount.setVisibility(View.INVISIBLE);
                okbtn.setVisibility(View.INVISIBLE);
                layout.setVisibility(View.INVISIBLE);
            }
        });
    }

    public void ActionBar() {
        final ActionBar abar = getActionBar();

        abar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_image));

        View viewActionBar = getLayoutInflater().inflate(R.layout.actionbar_title, null);
       /*        * Center the textview in the ActionBar !        */
        ActionBar.LayoutParams params = new ActionBar.LayoutParams(
                ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.MATCH_PARENT,
                Gravity.CENTER);
        TextView textviewTitle = (TextView) viewActionBar.findViewById(R.id.actionbar_textview);

        textviewTitle.setText("Custom Spinner");
        abar.setCustomView(viewActionBar, params);
        abar.setDisplayShowCustomEnabled(true);
        abar.setDisplayShowTitleEnabled(false);
        abar.setDisplayHomeAsUpEnabled(true);
        abar.setHomeButtonEnabled(true);
    }
}


...................................................................................................................................................................


try this...










Read more

 In this blog we will implement Single Item Select Custom Spinner  Android.

first , you can Create Custom Spinner xml Layout, drop dwon Some widegts for example LianerLayout ,textView and ListView. explain how to used..



Step 1: you can Create xml Gradient inside res/drawable folder.

text_cover.xml
...................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" 
android:padding="7dp">
<solid android:color="#FFFFFF"/>

<corners     
android:bottomRightRadius="3dp"     
android:bottomLeftRadius="3dp"     
android:topLeftRadius="3dp"     
android:topRightRadius="3dp"/>
 <stroke android:width="2dip" android:color="#dce0e2" />  
</shape>

..................................................................................................................................................................




activity_main.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"    
android:padding="10dp">


<ImageView        
android:layout_width="wrap_content"       
 android:layout_height="wrap_content"        
android:id="@+id/imageView"        
android:layout_gravity="center"        
android:src="@drawable/my_heder_img"/>

<LinearLayout       
 android:layout_width="match_parent"        
android:layout_height="wrap_content"        
android:layout_margin="4dp"        
android:orientation="horizontal"        
android:weightSum="2">
    
</LinearLayout>

 <LinearLayout        
android:layout_width="match_parent"        
android:layout_height="wrap_content"        
android:layout_margin="4dp"        
android:gravity="center_horizontal"       
 android:orientation="horizontal"        
android:weightSum="2">
<TextView            
android:layout_width="150dp"            
android:layout_height="48dp"
android:layout_weight="1"            
android:gravity="center_vertical"            
android:text="Select Item" />

        
<LinearLayout            
android:layout_width="match_parent"            
android:layout_height="wrap_content"            
android:layout_margin="4dp"            
android:layout_weight="1"           
android:gravity="center_horizontal"           
android:orientation="vertical"            
android:weightSum="2">

            
<TextView                
android:id="@+id/textView44"                
android:layout_width="fill_parent"               
android:layout_height="50dp"
android:background="@drawable/text_cover"                
android:drawableRight="@drawable/short_dwon"                
android:gravity="center_vertical"                
android:paddingLeft="18dp"                
android:textSize="18dp" />

            
<ListView                
android:id="@+id/spinAddGuest"                
android:layout_width="match_parent"               
android:layout_height="wrap_content"
android:background="@drawable/text_cover"
android:visibility="invisible" />        
</LinearLayout>
</LinearLayout>
</LinearLayout>


..................................................................................................................................................................



MainActivity.java
...................................................................................................................................................................

package com.example.sarvesh.testproject;

import android.app.ActionBar;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends Activity {
    ArrayList<String> item_array;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActionBar();

        setContentView(R.layout.activity_main);
        item_array = new ArrayList<String>();
        for (int i = 0; i < 10; i++) {
            item_array.add("Item" + i);
        }

        final ListView spinCount = (ListView) findViewById(R.id.spinAddGuest);
        final TextView text = (TextView) findViewById(R.id.textView44);

        text.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
                spinCount.setVisibility(View.VISIBLE);
            }
        });
        ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_single_choice, item_array);
        spinCount.setAdapter(spinnerArrayAdapter);
        spinCount.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        spinCount.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                text.setText(String.valueOf(item_array.get(position)));//get guest quantity                spinCount.setVisibility(View.INVISIBLE);
            }
        });
    }

    public void ActionBar() {
        final ActionBar abar = getActionBar();

        abar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_image));

        View viewActionBar = getLayoutInflater().inflate(R.layout.actionbar_title, null);
       /*        * Center the textview in the ActionBar !        */
        ActionBar.LayoutParams params = new ActionBar.LayoutParams(
                ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.MATCH_PARENT,
                Gravity.CENTER);
        TextView textviewTitle = (TextView) viewActionBar.findViewById(R.id.actionbar_textview);

        textviewTitle.setText("Custom Spinner");
        abar.setCustomView(viewActionBar, params);
        abar.setDisplayShowCustomEnabled(true);
        abar.setDisplayShowTitleEnabled(false);
        abar.setDisplayHomeAsUpEnabled(true);
        abar.setHomeButtonEnabled(true);
    }
}

...................................................................................................................................................................

try this......












Read more