• RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
Posted by Jack - - 1 comments


BLINKING TEXTVIEW

SOURCE CODE [Blink.java]

package com.YourPackageName;

import android.os.Handler;

public class Blink
{

                private int _interval;

                public int getInterval()
{
                                return _interval;
                }

                public void setInterval(int delay)
{
                                _interval = delay;
                }

                private Handler handler;
                private Runnable _tickHandler;
                private Runnable delegate;
                private boolean ticking;

                public boolean getIsTicking()
{
                                return ticking;
                }

                public Blink(int interval)
{
                                _interval = interval;
                                handler = new Handler();
                }

                public Blink(int interval, Runnable onTickHandler)
{
                                _interval = interval;
                                setOnTickHandler(onTickHandler);
                                handler = new Handler();
                }

                public void start(int interval, Runnable onTickHandler)
{
                                if (ticking)
                                                return;
                                _interval = interval;
                                setOnTickHandler(onTickHandler);
                                handler.postDelayed(delegate, _interval);
                                ticking = true;
                }

                public void start()
{
                                if (ticking)
                                                return;
                                handler.postDelayed(delegate, _interval);
                                ticking = true;
                }

                public void stop()
{
                                handler.removeCallbacks(delegate);
                                ticking = false;
                }

                public void setOnTickHandler(Runnable onTickHandler)
{
                                if (onTickHandler == null)
                                                return;

                                _tickHandler = onTickHandler;

                                delegate = new Runnable()
{
                                                public void run()
{
                                                                if (_tickHandler == null)
                                                                                return;
                                                                _tickHandler.run();
                                                                handler.postDelayed(delegate, _interval);
                                                }
                                };
                }

}

SOURCE CODE [TextViewBlinkExample.java]

package com. YourPackageName;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class TextViewBlinkExample extends Activity
{
                boolean blinkOn = false;

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
       
TextView tv = (TextView) findViewById (R.id.textview);       

                                Blink tmrBlink = new Blink(500, new Runnable()
{

public void run()
{
if (blinkOn)
{
tv.setVisibility(View.VISIBLE);
}
else
{
tv.setVisibility(View.INVISIBLE);
}
 blinkOn = !blinkOn;
}
});
tmrBlink.start();
}
}

Posted by Jack - - 0 comments


STRIKE OVER THE TEXT IN TEXTVIEW

TextView your_textview = (TextView) findViewById (R.id.textview1);
your_textview.setPaintFlags(your_textview.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

Posted by Jack - - 11 comments


SIMPLE TOGGLEBUTTON

SOURCE CODE [main.xml] is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
   
<ToggleButton android:id="@+id/togglebutton"
android:layout_width="150px"
android:layout_height="50px"
android:textOn="ON"
android:textOff="OFF" />

</LinearLayout>

SOURCE CODE [ToggleButtonExample.java] is

package com.ToggleButtonExample;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
import android.widget.ToggleButton;

public class ToggleButtonExample extends Activity
{
ToggleButton tb;

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
                                setContentView(R.layout.main);

                                tb = (ToggleButton) findViewById(R.id.togglebutton);
                                tb.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(),
"Button is "+tb.getText().toString(),
Toast.LENGTH_LONG).show();
                                                }
                                });
                }
}

The OUTPUT will be


https://lh6.googleusercontent.com/_xnrF0YSUul8/Tb-gTjj4FtI/AAAAAAAAAJU/NYefHbaTYtg/togglebutton1.png

https://lh6.googleusercontent.com/_xnrF0YSUul8/Tb-gT-vTttI/AAAAAAAAAJY/o7XA3gkvhjU/togglebutton2.png

Posted by Jack - - 3 comments


SIMPLE RATINGBAR

SOURCE CODE [main.xml] is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
   
<RatingBar android:id="@+id/ratingbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
   
                <TextView android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
   
</LinearLayout>

SOURCE CODE [RatingBarExample.java] is

package com.RatingBarExample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.RatingBar.OnRatingBarChangeListener;

public class RatingBarExample extends Activity
{

                RatingBar ratingbar;
                TextView ratings;

                public void onCreate(Bundle savedInstanceState)
{
                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.main);

                                ratings = (TextView) findViewById(R.id.rating);
                                ratingbar = (RatingBar) findViewById(R.id.ratingbar);

                                ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener()
{
                                                public void onRatingChanged(RatingBar ratingBar, float rating,
                                                                                boolean fromUser)
{
                                                                // TODO Auto-generated method stub
                                                                ratings.setText("The Rating is " + rating);
                                                }
                                });
                }
}

The OUTPUT will be

https://lh5.googleusercontent.com/_xnrF0YSUul8/Tb-Vkpz70LI/AAAAAAAAAJI/RNnXgVY1yN0/ratingbar1.png

https://lh4.googleusercontent.com/_xnrF0YSUul8/Tb-VlEhsoLI/AAAAAAAAAJM/NqgawsD7pYA/ratingbar2.png

Posted by Jack - - 15 comments


SIMPLE SEEKBAR

SOURCE CODE [main.xml] is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView  android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<SeekBar android:id="@+id/seekbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="100"
android:minWidth="250px"  />

<TextView android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout


SOURCE CODE [SeekBarExample.java] is

package com.SeekBarExample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class SeekBarExample extends Activity
{
SeekBar seekbar;
TextView value;

public void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);
setContentView(R.layout.main);
       
value = (TextView) findViewById(R.id.textview);
 seekbar = (SeekBar) findViewById(R.id.seekbar);
       
                                seekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar seekBar, int progress,
                                                                boolean fromUser)
{
                                                                // TODO Auto-generated method stub
                                                                value.setText("SeekBar value is "+progress);
                                                }

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

                                                public void onStopTrackingTouch(SeekBar seekBar)
{
                                                                // TODO Auto-generated method stub
                                                }
});
}
}


The OUTPUT will be

 https://lh4.googleusercontent.com/_xnrF0YSUul8/Tb6n7KrBJeI/AAAAAAAAAI0/wgCsIaL20qE/simple_seekbar1.png

https://lh5.googleusercontent.com/_xnrF0YSUul8/Tb6n7NAeuMI/AAAAAAAAAI4/oiwWqBTR8cE/simple_seekbar2.png