Android Switch Button Tutorial

Android Switch Button:

SwitchCompat is a version of the switch widget which on devices back to API v7. It does not make any attempt to use the platform provided widget on those devices which it is available normally.

A switch is a two state toggle switch widget that can select between two options. The user may drag the thump back or forth to choose the selected option, or simply tap to toggle as if were a checkbox.

XML File:


Activity file:



You can watch video demo here:





Android ToggleButton Tutorial

Android ToggleButton:

Android toggle button can be used to display checked/unchecked (On/Off) state on the button.

It is beneficial if user have to change the setting between two states. It can be used On/Off sound, Wifi, Bluetooth, etc.

Since, Android 4.0 there is another type of toggle called switch that provides slider control.

Android ToggleButton and Switch both are the subclasses of CompoundButton Class.

xml file:

Activity file:


You can watch video demo here:





AutoCompletetextView Tutorial- android

A AutoCompleteTextView is an editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.

Let's demonstrate the AutoCompleteTextView:
So, You can add AutoCompleteTextview in your activity layout as:


android:layout_height="wrap_content"
android:layout_below="@id/hello"
android:ems="10"
android:hint="auto complete textview"
android:layout_marginTop="8dp"
android:id="@+id/autocomplete"/>

and finally, your activity.java file can be as:

public class MainActivity extends AppCompatActivity {
    AutoCompleteTextView text;
    String[] languages={"android", "java","IOS","JDBC","C#","C++","C"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text=(AutoCompleteTextView) findViewById(R.id.autocomplete);
        ArrayAdapter adapter=new ArrayAdapter(this, android.R.layout.simple_list_item_1,languages);
        text.setAdapter(adapter);
        text.setThreshold(1);
    }
}
 You can watch video demo here:



MultiAutoCompleteTextView Tutorial- android

A MultiAutoCompleteTextView is an editable text view, extending AutoCompleteTextView, that can show completion suggestions for the substring of the text where the user is typing instead of necessarily for the entire thing.

Let's demonstrate a MultiAutoCompleteTextView:
In your layout file you can add it as:


        
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/autocomplete"
        android:layout_marginTop="8dp"
        android:hint="multi auto complete text view"
        android:id="@+id/multi"
        android:ems="10"/>

SO, your activity. java can be as:

public class MainActivity extends AppCompatActivity {
    MultiAutoCompleteTextView text1;
    String[] languages={"android", "java","IOS","JDBC","C#","C++","C"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text1=(MultiAutoCompleteTextView) findViewById(R.id.multi);
        ArrayAdapter adapter=new ArrayAdapter(this, android.R.layout.simple_list_item_1,languages);
     
        text.setThreshold(1);
        text1.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    }

You Can watch a video demo at: