Using SeekBar

For adding a seekbar to your layout file (res/layout/*.xml)

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

For adding the functionality part of the SeekBar, copy and paste the below code in your onCreate() function of JAVA File.

Note: Below the SetContentView() line in onCreate() function.

		SeekBar sb = (SeekBar) findViewById(R.id.seekBar1);
		sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				Toast.makeText(MainActivity.this, "stop"+Integer.toString(progressed),
						Toast.LENGTH_SHORT).show();
			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				// TODO Auto-generated method stub
				progressed = progress;
			}
		});

Note: Make sure you declare a variable in Java Class file. Before the function and inside the class file at top.

int progressed = 0;

Save the changes and run your Android Application in Emulator or an Android Device. Post your comments.

Using Radio Group and Radio Button

For adding a group of radio buttons to your layout file (res/layout/*.xml)

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/radio0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="One" />

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Two" />

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Three" />
    </RadioGroup>

For adding the functionality part of the Radio Group and Radio Button, copy and paste the below code in your onCreate() function of JAVA File.

Note: Below the SetContentView() line in onCreate() function.

		RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
		rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				// TODO Auto-generated method stub
				//int selection = rg.getCheckedRadioButtonId();
				RadioButton rb = (RadioButton) findViewById(checkedId);
				Toast.makeText(MainActivity.this, rb.getText() ,
						Toast.LENGTH_SHORT).show();
			}
		});

Save the changes and run your Android Application in Emulator or an Android Device. Post your comments.

Using Switch Controls

A Switch is a two-state toggle switch widget that can select between two options. Its similiar to Wireless on/off method.

For adding a Switch to your layout file (res/layout/*.xml)

    <Switch
        android:id="@+id/switch1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Switch" />

For adding the functionality part of the Switch, copy and paste the below code in your onCreate() function of JAVA File.

Note: Below the SetContentView() line in onCreate() function.

		Switch sw = (Switch) findViewById(R.id.switch1);
		sw.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				// TODO Auto-generated method stub
				if (isChecked) {
					Toast.makeText(MainActivity.this, "true",
							Toast.LENGTH_SHORT).show();
				} else {
					Toast.makeText(MainActivity.this, "false",
							Toast.LENGTH_SHORT).show();
				}
			}
		});

Note: Make sure you change the minSdkVersion to 14 in AndroidManifest.xml file.

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="18" />

Save the changes and run your Android Application in Emulator or an Android Device. Post your comments.

Using Toggle Button

A toggle button allows the user to change a setting between two states.

For adding a ToggleButton to your layout file (res/layout/*.xml)

    <ToggleButton
        android:id="@+id/toggleButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ToggleButton" />

For adding the functionality part of the ToggleButton, copy and paste the below code in your onCreate() function of JAVA File.

Note: Below the SetContentView() line in onCreate() function.

		ToggleButton tb = (ToggleButton) findViewById(R.id.toggleButton1);
		tb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				// TODO Auto-generated method stub
				if (isChecked) {
					Toast.makeText(MainActivity.this, "true",
							Toast.LENGTH_SHORT).show();
				} else {
					Toast.makeText(MainActivity.this, "false",
							Toast.LENGTH_SHORT).show();
				}
			}
		});

Save the changes and run your Android Application in Emulator or an Android Device. Post your comments.

Display Conditional Pages

I have been trying to exclude buddypress pages from wp_nav_menu.

function get_ID_by_page_name() {
global $wpdb;
$page_name = array('Activity','Forums','Groups','Members','Register','Activate');
//print_r($page_name);
for($i=0;$i&lt;sizeof($page_name);$i++)
{
//echo $page_name[$i];
$page_name_id = $wpdb-&gt;get_var(&quot;SELECT ID FROM $wpdb-&gt;posts WHERE post_name = '&quot;.$page_name[$i].&quot;' AND post_type = 'page'&quot;);
?&gt;
&lt;style&gt;
.page-item-&lt;?php echo $page_name_id; ?&gt; {display:none; }
&lt;/style&gt;
&lt;?php
}
}
echo get_ID_by_page_name();

Global search through wordpress multisite network

<?php
$searchfor = get_search_query(); // Get the search query for display in a headline
?>
<h1>Search results for '<?php echo $searchfor; ?>'</h1>
<?php
$query_string=esc_attr($query_string); // Escaping search queries to eliminate potential MySQL-injections
$blogs = get_blog_list( 0,'all' );
$search = new WP_Query($query_string);
if ($search->found_posts>0) {
foreach ( $blogs as $blog ):
switch_to_blog($blog['blog_id']);
foreach ( $search->posts as $post ) {
setup_postdata($post);
$author_data = get_userdata(get_the_author_meta('ID'));
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<p>
<span><?php the_time('Y/m/d') ?></span>
By <?php the_author_posts_link();?> </p>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div id="entry-content"><?php
the_excerpt();
?>
</div>
</div>
<?php
}
endforeach;
else
{
echo "Not Found";
}
restore_current_blog(); // Reset settings to the current blog
?>

Activate / Deactivate plugin from theme

Paste the below code in your ‘functions.php’

function deactivate_plugin_conditional() {
    if ( is_plugin_active('plugin_folder_name/plugin_name.php') ) {
    activate_plugins('plugin_folder_name/plugin_name.php');    
    }
    else
    {
    deactivate_plugins('plugin_folder_name/plugin_name.php');    
    }
}
add_action( 'admin_init', 'deactivate_plugin_conditional' );