Example of Spinner Control in Android





1. Create XML file for layout
activity_spinner_demo.xml


  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="dhaval.SpinnerDemo">
<TextView
android:id="@+id/lblCatList"
android:text="Select Category"
android:textSize="20dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Spinner
android:layout_width="fill_parent"
android:layout_below="@+id/lblCatList"
android:layout_height="wrap_content"
android:id="@+id/mSpnStudent"
/>
</RelativeLayout>

2.After that Put Following Code in Your Class File
package dhaval;

import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import com.tristate.truepal.R;
public class SpinnerDemo extends Activity implements AdapterView.OnItemSelectedListener {
Spinner mSpnStudent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spinner_demo);
mSpnStudent=(Spinner)findViewById(R.id.mSpnStudent);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.mStudent, android.R.layout.simple_spinner_item);
mSpnStudent.setOnItemSelectedListener(this);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
mSpnStudent.setAdapter(adapter);
}
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
Toast.makeText(getBaseContext(),adapterView.getItemAtPosition(i)+"",Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
}
3.And also put following code in your string file
<string-array name="mStudent">
<item>Dhaval</item>
<item>Gopal</item>
<item>Mohit</item>
<item>Amit</item>
<item>Rupal</item>
<item>Upasana</item>
<item>Ajay</item>
<item>Vishnu</item>
</string-array>

SQL lite example in android

First Require to Create Layout Like Following.






activity_main.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txtName"
        android:hint="Name"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Save Data"
        android:id="@+id/btnSave"
        android:layout_below="@+id/txtName"
        android:layout_centerHorizontal="true" />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/lstName"
        android:layout_below="@+id/btnSave"
        android:layout_centerHorizontal="true" />
</RelativeLayout>


raw.xml             / / file for row



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"  android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/lblName"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

After th create Following Classes 

 DBHelper.java

 package pack.com.contactdemo;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper{

    //table name
    public static final String TABLE_NAME="contact";

    //table column
    public static final String _ID="_id";
    public static final String NAME="name";

    //database
    public static final String DATABASE_NAME="CONTACTS.DB";

    //version
    public static final int version=1;

    //table query
    public static final String QUERY_TABLE="create table " + TABLE_NAME + "(" + _ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME + " TEXT NOT NULL);";

    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null, version);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(QUERY_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }
}

 

SQLController.java

 package pack.com.contactdemo;


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.sql.SQLException;

public class SQLController {
    public DBHelper dbHelper;
    private Context ourcontext;
    private SQLiteDatabase database;

    public SQLController(Context c) {
        ourcontext = c;
    }

    public SQLController open() throws SQLException {
        dbHelper = new DBHelper(ourcontext);
        database = dbHelper.getWritableDatabase();
        return this;
    }

    public void close() {
        dbHelper.close();
    }

    public void insert(String name) {
        ContentValues contentValue = new ContentValues();
        contentValue.put(DBHelper.NAME, name);

     database.insert(DBHelper.TABLE_NAME,null,contentValue);
    }

    public Cursor fetch() {
        String[] columns = new String[] { DBHelper._ID, DBHelper.NAME };
        Cursor cursor = database.query(DBHelper.TABLE_NAME, columns, null,
                null, null, null, null);
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }
}

MyAdpter.java

 package pack.com.contactdemo;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class MyAdpter extends BaseAdapter
{
    Context context;
    String name;


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

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return null;
    }
}


MainActivity.java

 package pack.com.contactdemo;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

import java.sql.SQLException;


public class MainActivity extends Activity implements View.OnClickListener {

    EditText txtName;
    DBHelper dbHelper;
    SQLController dbcon;
  //  Long num;
    String name;

    Button btnSave;
    ListView lstName;

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


        initialize();
        initializeListView();
        btnSave.setOnClickListener(this);

    }

    public void initialize() {
        txtName = (EditText) findViewById(R.id.txtName);
        btnSave = (Button) findViewById(R.id.btnSave);
        lstName = (ListView) findViewById(R.id.lstName);
        dbHelper=new DBHelper(MainActivity.this);
        dbcon=new SQLController(MainActivity.this);
        try {
            dbcon.open();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public void initializeListView()
    {
        Cursor cursor = dbcon.fetch();
        String[] from = new String[] { DBHelper.NAME};
        int[] to = new int[] { R.id.lblName };

       SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
              R.layout.raw, cursor, from,to);

       adapter.notifyDataSetChanged();
        lstName.setAdapter(adapter);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.newName) {
            Toast.makeText(getBaseContext(),"You Selected New",Toast.LENGTH_SHORT).show();
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View v) {
                name=txtName.getText().toString();
        Log.i("Name",name);
                if (name==" ")
                {

                    Toast.makeText(getBaseContext(), " Put Name Please", Toast.LENGTH_SHORT).show();
                    initializeListView();
                }
        else
                {
                    dbcon.insert(name);
                    Toast.makeText(getBaseContext(), "Data Sucessfully Saved", Toast.LENGTH_SHORT).show();
                    initializeListView();
                }

        }
    }


 


How to set offline gradle in android studio

1. Before proceed for set gradle Rquire to download offline Gradle file .

2. From this URL you can download different different version of gradle , https://gradle.org/downloads/.


3. After download open android studio and select file menu and click on setting . Dialog is open.




4. Then select “Build,Execution,Deployment” option from side menu then after select Build from Right so they display gradle option select them.




Generate Signed APK in android using Android Studio for publish Application


Generate Signed APK in android using Android Studio for publish Application

1. Before Generate signed apk you require you project error free and cleaned ,So before proceed you clean your project and build project.

2. After that open “Build” menu and “Select Generate Signed APK”.



3. After then Click on Generate Signed APK pop-up Like Following Dialog Fill Details .



4. If you don’t have key store then click on Create new.. for create new key store and if you have already then select and click next,and After open one another Dialog in that select release and click finish then after your APK is ready for publish.




Publish your Android Application on Google Play Store


1. Create Publisher Account :Be for Publish your Application on Google Play store you Require Play store publisher account,so if you don’t have account go on this URL and https://play.google.com/apps/publish/ activate your account currently fee of play store publisher account $25 .

2. After creation Successful of your play store account you can upload number of application on play store.

3. Before you publish your app you must have a .apk file signed by private key and you must secure the key because the key is the only way to update your application in future. You can read How to Sign Android App .

4. After then go on this URL https://play.google.com/apps/publish/ sign in using your account details and After Click on Add new application Button.

5. You will be prompted to Give the Title of the application, Give a goog title and click on Upload apk.

6. Upload your signed .apk file.

7. Click on Store Listing button in left pane and upload all the required things like App Detail, Snapshots, Icon etc.

8. Click on Pricing and Distribution: Select the Countries in which you want to distribute your app.

You can distribute you app free of cast or you can fix a price for your app. To distribute your paid apps you need to create a merchant account. You can create merchant account Here. Google Wallet Merchant Center 

Send Email In Android Using Costume Layout

MailSenderActivty.java

YOUR PACKAGE;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class MailSenderActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final Button send = (Button) this.findViewById(R.id.send);
        send.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // TODO Auto-generated method stub
                try {  
                    GMailSender sender = new GMailSender("username@gmail.com", "password");
                    sender.sendMail("This is Subject",  
                            "This is Body",  
                            "user@gmail.com",  
                            "user@yahoo.com");  
                } catch (Exception e) {  
                    Log.e("SendMail", e.getMessage(), e);  
                }
            }
        });
    }
}


GMailSender.java


YOUR PACKAGE;
import javax.activation.DataHandler;   
import javax.activation.DataSource;   
import javax.mail.Message;   
import javax.mail.PasswordAuthentication;   
import javax.mail.Session;   
import javax.mail.Transport;   
import javax.mail.internet.InternetAddress;   
import javax.mail.internet.MimeMessage;   
import java.io.ByteArrayInputStream;   
import java.io.IOException;   
import java.io.InputStream;   
import java.io.OutputStream;   
import java.security.Security;   
import java.util.Properties;   

public class GMailSender extends javax.mail.Authenticator {   
    private String mailhost = "smtp.gmail.com";   
    private String user;   
    private String password;   
    private Session session;   

    static {   
        Security.addProvider(new com.provider.JSSEProvider());   
    }  

    public GMailSender(String user, String password) {   
        this.user = user;   
        this.password = password;   

        Properties props = new Properties();   
        props.setProperty("mail.transport.protocol", "smtp");   
        props.setProperty("mail.host", mailhost);   
        props.put("mail.smtp.auth", "true");   
        props.put("mail.smtp.port", "465");   
        props.put("mail.smtp.socketFactory.port", "465");   
        props.put("mail.smtp.socketFactory.class",   
                "javax.net.ssl.SSLSocketFactory");   
        props.put("mail.smtp.socketFactory.fallback", "false");   
        props.setProperty("mail.smtp.quitwait", "false");   

        session = Session.getDefaultInstance(props, this);   
    }   

    protected PasswordAuthentication getPasswordAuthentication() {   
        return new PasswordAuthentication(user, password);   
    }   

    public synchronized void sendMail(String subject, String body, String sender, String recipients) throws Exception {   
        try{
        MimeMessage message = new MimeMessage(session);   
        DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));   
        message.setSender(new InternetAddress(sender));   
        message.setSubject(subject);   
        message.setDataHandler(handler);   
        if (recipients.indexOf(',') > 0)   
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));   
        else  
            message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));   
        Transport.send(message);   
        }catch(Exception e){

        }
    }   

    public class ByteArrayDataSource implements DataSource {   
        private byte[] data;   
        private String type;   

        public ByteArrayDataSource(byte[] data, String type) {   
            super();   
            this.data = data;   
            this.type = type;   
        }   

        public ByteArrayDataSource(byte[] data) {   
            super();   
            this.data = data;   
        }   

        public void setType(String type) {   
            this.type = type;   
        }   

        public String getContentType() {   
            if (type == null)   
                return "application/octet-stream";   
            else  
                return type;   
        }   

        public InputStream getInputStream() throws IOException {   
            return new ByteArrayInputStream(data);   
        }   

        public String getName() {   
            return "ByteArrayDataSource";   
        }   

        public OutputStream getOutputStream() throws IOException {   
            throw new IOException("Not Supported");   
        }   
    }   

JSSEProvider.java


import java.security.AccessController;
import java.security.Provider;

public final class JSSEProvider extends Provider {

    public JSSEProvider() {
        super("HarmonyJSSE", 1.0, "Harmony JSSE Provider");
        AccessController.doPrivileged(new java.security.PrivilegedAction<Void>() {
            public Void run() {
                put("SSLContext.TLS",
                        "org.apache.harmony.xnet.provider.jsse.SSLContextImpl");
                put("Alg.Alias.SSLContext.TLSv1", "TLS");
                put("KeyManagerFactory.X509",
                        "org.apache.harmony.xnet.provider.jsse.KeyManagerFactoryImpl");
                put("TrustManagerFactory.X509",
                        "org.apache.harmony.xnet.provider.jsse.TrustManagerFactoryImpl");
                return null;
            }
        });
    }
}

Get Data From Server in ANdroid

First Require To Post Request on Server


HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("passhearurldata");//Pass Hear Your Url
try {
    HttpResponse response = httpclient.execute(httpget);
    if(response != null) {
        String line = "";
        InputStream inputstream = response.getEntity().getContent();
        line = conStr(inputstream);
        Toast.makeText(this, line, Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(this, "Unable to complete your request", Toast.LENGTH_LONG).show();
    }
} catch (ClientProtocolException e) {
    Toast.makeText(this, "Caught ClientProtocolException", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
    Toast.makeText(this, "Caught IOException", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
    Toast.makeText(this, "Caught Exception", Toast.LENGTH_SHORT).show();
}

After That You Require Parse Server Response Into String


private String conStr(InputStream is) {
    String line = "";
    StringBuilder total = new StringBuilder();
    BufferedReader rd = new BufferedReader(new InputStreamReader(is));
    try {
        while ((line = rd.readLine()) != null) {
            total.append(line);
        }
    } catch (Exception e) {
        Toast.makeText(this, "Stream Exception", Toast.LENGTH_SHORT).show();
    }
    return total.toString();
}

How to Store Data in Preference in android

There are three mode available for store data in Preference

          MODE_WORLD_READABLE
          MODE_WORLD_WRITEABLE
          MODE_PRIVATE

Store,Read,Remove,Clear Data from Shared Preference

SharedPreferences prefrance = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
Editor edit= prefrance.edit();
 
 /*********Data as KEY/VALUE pair *******************/

 edit.putBoolean("key_name1", true);// Saving boolean - true/false
 edit.putInt("key_name2", "int value");// Saving integer
 edit.putFloat("key_name3", "float value");
 edit.putLong("key_name4", "long value");
 edit.putString("key_name5", "string value");
// Save the changes in SharedPreferences
 edit.commit(); // commit changes

/**************** Get Preferences data *******************/

 // If value for key not exist then return second param value - In this case null
 prefrance.getBoolean("key_name1", null);
 prefrance.getInt("key_name2", null);
 prefrance.getFloat("key_name3", null);
 prefrance.getLong("key_name4", null);
 prefrance.getString("key_name5", null);

/********* Deleting Key value from Preferences **********/
 edit.remove("key_name3"); // will delete key key_name3
 edit.remove("key_name4"); // will delete key key_name4

 // Save the changes in Preferences
 edit.commit(); // commit changes

 /********** Clear all data from Preferences *************/
 edit.clear();
 edit.commit(); // commit changes

Convert Timestamp into Date and Time

Public String getDatafTimeStamp(long timestamp){
java.util.Date time=new java.util.Date(timestamp*1000);
          SimpleDateFormat pre = new SimpleDateFormat("EEE MM dd HH:mm:ss zzz yyyy");
                           //Hear Define your returning date formate
          return pre.format(time);
}

Send sms in android Application using Intent and SmsManager API

Using SmsManager API

                    SmsManager smsManager = SmsManager.getDefault();
                    smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);

Built-in SMS application
                 
                    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                    sendIntent.putExtra("sms_body", "default content");
                    sendIntent.setType("vnd.android-dir/mms-sms");
                    startActivity(sendIntent);

Require Following Permission for Both
          <uses-permission android:name="android.permission.SEND_SMS" />

Find Different Between to Date in days in android

Dtae like ="03-06-2015"

public long getDiffrent(String date) {

        String[] arraydtae= new String[3];
        arraydtae= datenew.split("-"); // Hear you require to define date-month separator like hear "-"

        int dd = Integer.parseInt(arra[0]);
        int mm = Integer.parseInt(arra[1]);
        int yy = Integer.parseInt(arra[2]);

        Calendar thatDay = Calendar.getInstance();
        thatDay.set(Calendar.DAY_OF_MONTH, dd);
        thatDay.set(Calendar.MONTH, mm - 1); // 0-11 so 1 less
        thatDay.set(Calendar.YEAR, yy);

       Calendar today = Calendar.getInstance();
        long diff = today.getTimeInMillis() - thatDay.getTimeInMillis(); //result in millis
        long days = diff / (24 * 60 * 60 * 1000);
     
        return days;
}

Pass Data Between to Activity in Android

First you will create create in your Base or First Activity.

Intent i = new Intent(getApplicationContext(), Activity2.class);
i.putExtra("NameofKey","value");
startActivity(i);

After that go on your second Activity means Activity2.java and Put Following Code.

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("NameofKey");
}

Custom switch with smooth scrolling in android using seek bar.

you require to create first one drawable xml file witch specify your switch background. 

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" >
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<size
android:height="48dip"
android:width="48dip" />
<gradient
android:angle="270"
android:centerColor="#806CA5BC"
android:centerX="0.50"
android:centerY="0.50"
android:endColor="#66C2E0"
android:startColor="#517C8D"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate> 

After Create this drawable file you require to create layout for switch.

<RelativeLayout
                    android:id="@+id/layEmailsub1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content">

                    <RelativeLayout
                        android:id="@+id/laySwitchEmail"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:background="@drawable/switch_off_"></RelativeLayout>  //one layout with you switch initial background

                    <SeekBar //create seek bar require for drags thumb
                        android:id="@+id/switchEmail"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignBottom="@id/laySwitchEmail"
                        android:layout_alignLeft="@id/laySwitchEmail"
                        android:layout_alignRight="@id/laySwitchEmail"
                        android:layout_alignTop="@id/laySwitchEmail"
                        android:layout_centerInParent="true"
                        android:indeterminate="false"
                        android:max="100"
                        android:paddingLeft="15dp"
                        android:paddingRight="15dp"
                        android:progress="0"
                        android:progressDrawable="@drawable/styled_progress_swich"  // specify drawable file witch is initialy we created
                        android:thumb="@drawable/white_circle" /> //hear specify thumb of switch
                </RelativeLayout>

And After put this code in your class file

//create following variable 
SeekBar switchEmail;
RelativeLayout laySwitchEmail;
Boolean alertScribe = null;
//initialise above variable
switchEmail = (SeekBar) findViewById(R.id.switchEmail);
laySwitchEmail = (RelativeLayout) findViewById(R.id.laySwitchEmail);
//after all this set one switchEmail seek bar change listener like following 
switchEmail.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int prograssvalue = 0;

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
prograssvalue = progress;
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
if (prograssvalue <= 50) {
swichOpt(1, 0);
} else {
swichOpt(1, 1);
}
}
});
// method for perform switch operation enable or disable
private void swichOpt(int switchid, int val) {
switch (switchid) {
case 1:
if (val == 0) {
switchEmail.setProgress(0);
laySwitchEmail.setBackgroundResource(R.drawable.switch_off_);
} else {
switchEmail.setProgress(100);
laySwitchEmail.setBackgroundResource(R.drawable.switch_on_);
}
break;
}
}