Thursday, 9 January 2014

Android Spinner View Text Not Visible


Android Spinner View Text Not Visible 

(White background on Text Also showing White Color)

---------------------------------------------------------------------------------------------------------------------------------


<Spinner
     android:id="@+id/courselist"     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_weight="1" />
Spinner spnrcourse=(Spinner)findViewById(R.id.courselist);
String[] courselist = {"Java", "Cpp", "Oracle","Android" };
spnrcourse.setAdapter(new ArrayAdapter(getApplicationContext(), 
android.R.layout.simple_dropdown_item_1line, courselist));

Replace getApplicationContext() to getBaseContext()
                              (OR)
Replace getApplicationContext() to this (if above is not working)
                              (OR)
Replace getApplicationContext() to getActivity() (if you are Using Fragment) 


Wednesday, 8 January 2014

Mutable and Immutable Object in Java



package raja.JavaPages4All;

import java.util.Date;

/**
 * @author Raja(JavaPages4All)
 */
public class TestPojo 
{
 private String blogName;
 private Date date;

 public TestPojo(String blogName,Date date)
 {
  this.blogName=blogName;
  this.date = date;
 }

 public String getBlogName()
 {
  return this.blogName;
 }

 public Date getDate()
 {
  return this.date;
 }
}



package raja.JavaPages4All;

import java.util.Date;

public class ImmutableTest 
{

 /**
  * @author Raja(JavaPages4All)
  */
 public static void main(String[] args) 
 {
  /*
   * String Class is Immutable.
   * Date Class is Mutable. 
   */
  String str="JavaPages4All";
  Date myDate = new Date();

  TestPojo pojo =new TestPojo(str,myDate);

  /**
   * Getting Values from TestPojo Reference Object(When First Time) 
   */
  System.out.println(pojo.getBlogName());
  System.out.println( pojo.getDate() );

  /**
   * String str Object value changing so it is Creating Newly(Immutable).
   * Date myDate Object value changing so it is Updated the 
   * Previous Object myDate Value(Mutable)
   */
  str="Raja";
  myDate.setMonth( myDate.getMonth() + 1 );

  /**
   * Getting Values from TestPojo Reference Object
   * (When Second Time object Values Changed)
   */
  System.out.println(pojo.getBlogName()+"  "+str);
  System.out.println( pojo.getDate() );
 }

}




Mutable vs Immutable in Java


Mutable Objects: When you have a reference to an instance of an object, the contents of that instance can be altered

Immutable Objects: When you have a reference to an instance of an object, the contents of that instance cannot be altered

(OR)
Immutable objects are simply objects whose state (the object's data) cannot change after construction

Immutability and Instances

To demonstrate this behaviour, we'll use java.lang.String as the immutable class and java.awt.Point as the mutable class.
package raja.JavaPages4all;

import java.awt.Point;

public class Immutability  
{
 /**
  * @author Raja(JavaPages4All)
  * @param args
  */
 public static void main(String[] args) 
 {
  Point pt= new Point( 0, 0 );
  System.out.println( pt);
  pt.setLocation( 1.0, 0.0 );
  System.out.println( pt);

  String str= new String( "old String" );
  System.out.println( str);
  str.replaceAll( "old", "new" );
  System.out.println( str);
 }
}
In case you can't see what the output is, here it is:
 java.awt.Point[0.0, 0.0]
 java.awt.Point[1.0, 0.0]
 old String
 old String

We are only looking at a single instance of each object, but we can see that the contents of pt has changed, but the contents of str did not. To show what happens when we try to change the value of str, we'll extend the previous example.
package raja.JavaPages4all;

import java.awt.Point;

public class Immutability  
{
 /**
  * @author Raja(JavaPages4All)
  * @param args
  */
 public static void main(String[] args) 
 {
  Point pt= new Point( 0, 0 );
  System.out.println( pt);
  pt.setLocation( 1.0, 0.0 );
  System.out.println( pt);

  String str= new String( "old String" );
  System.out.println( str );
  str= new String( "new String" );
  System.out.println( str );
 }
}
The output from this is:
 old String
 new String
Now we find that the value displayed by the str variable has changed. We have defined immutable objects as being unable to change in value, so what is happening? Let's extend the example again to watch the str variable closer.
package raja.JavaPages4all;


public class Immutability  
{
 /**
  * @author Raja(JavaPages4All)
  * @param args
  */
 public static void main(String[] args) 
 {
  //Comparison
  String str = new String( "old String" );
  String myCache = str ;
  System.out.println( "String Comparison: " + str.equals( myCache ) );
  System.out.println( "Object Comparison:  " + ( str == myCache ) );

  str = "not " + str ;
  System.out.println( "String Comparison: " + str.equals( myCache ) );
  System.out.println( "Object Comparison:  " + ( str == myCache ) );
 }
}
The result from executing this is:
 String Comparison: true
 Object Comparison: true
 String Comparison: false
 Object Comparison: false
What this shows is that variable str is referencing a new instance of the String class. The contents of the object didn't change; we discarded the instance and changed our reference to a new one with new contents.


Sunday, 29 December 2013

Snow Effect On The Blogger Mouse Cursor


  • Add Snow Falling Effect In Blogger
  • Go To Blogger > Layout
  • Add a HTML / JavaScript Gadget
  • Paste the following code in it,
  • Leave the title empty and click Save.

          <script type="text/javascript" src="http://dl.dropboxusercontent.com/s/ueqjg2s5b113nmt/079_green_00ff00_24work.blogspot.com.js"></script><a href="http://24work.blogspot.com/" target="_blank" title="Blogger Tricks"><img src="https://bitly.com/24workpng1" alt="Blogger Tricks" border="0" style="position: fixed; bottom: 10%; right: 0%; top: 0px;" ></a>

(OR)
if you want more Effects Click

ADD RUNNING TRUCKS IN BLOGGER


  • Login to Blogger > Dashborad
  • Click on Drop Down Menu and select Layout
  • Add a HTML/JavaScript Gadget
  • Paste below code in it. 
<div style="position: fixed; z-index: 65535; left: 0px; bottom: -3px; width:100%;"> <marquee><a href="http://www.facebook.com/WidgetGenerators" target="blank"> <abbr title="Follow us at Facebook"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYeU4CkSZcyLthOhDuE4wdw09hjZHFomPuamCqqbbIAlahZUg9AN5HH_y6TkfMAgAShPXt2utTbooSLgO9luEqIfmXva7Wd6z3Tl2agfML8Xudn4NkyEfvZ81HT4277yPEy8Lasnu2S_8i/s1600/Social-Truck_fb2.png" width="120px" height="100px"/> </abbr> </a> <a href="http://feeds.feedburner.com/WidgetGenerators" target="blank"> <abbr title="Subscribe Our Feeds"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBR_4XRiiAek9k_qefDrOYaQpG4MhFmzc-rZLV2cWejHVnataDjLn5xDxCPKAPh9dOSYN91NmbQ13sQts_ReKqidqd2dIhSNBnYJhQmfESXT_52_Qb9xB9hGiRH85Q91MEqcBSREIgz8fm/s1600/Social-Truck_rss.png" width="120px" height="100px"/> </abbr> </a><a href="http://twitter.com/WidgetGenerator" target="blank"> <abbr title="Follow Us on Twitter"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHyPIQ1lLujSLOVZQJQ4q0SU3oU2w39oL8DkjmECrgUF0J9T3eX166uc_12SxcvOVviiE5TPeLZWx8dLwloYT6JI8dNMuNQMTeBQaSVpkSO9YruxUBO0AUZFI9D7HelS32V1emQXxZhXcP/s1600/Social-Truck_twi.png" width="120px" height="100px"/> </abbr> </a> </marquee></div>

  •  Save your Widget.
  • Replace it WidgetGenerator with your Facebook Username
  • Replace it WidgetGenerator with your Feed Burner Username.
  • Replace it WidgetGenerator with your Twitter Username

Add Snow Effect to Website or BlogSpot

Add Snow Falling Effect In Blogger

  • Go To Blogger > Layout
  • Add a HTML / JavaScript Gadget
  • Paste the following code in it,
  • Leave the title empty and click Save.

<script src="https://raw.github.com/scottschiller/Snowstorm/master/snowstorm-min.js"></script> 

(or)

<script type="text/javascript"> 
  //Configure below to change URL path to the snow image 
  var snowsrc="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLUlJnmIM1O9sgBpoAr6gbmbawc5hHelUVsvLJ-3ISzbkI81-VQq1181hpm7LlMiutd3XY-RIFuuqObNrdI12RZK75FjVaofvw2qMCSae5yjIAyoBm43EA1RsihWULPXdUijMRGWImFkA/s400/snow.gif" 
  // Configure below to change number of snow to render 
  var no = 30
  // Configure whether snow should disappear after x seconds (0=never): 
  var hidesnowtime = 0; 
  // Configure how much snow should drop down before fading ("windowheight" or "pageheight") 
  var snowdistance = "pageheight"; 
///////////Stop Config////////////////////////////////// 
  var ie4up = (document.all) ? 1 : 0; 
  var ns6up = (document.getElementById&&!document.all) ? 1 : 0; 
    function iecompattest(){ 
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body 
    } 
  var dx, xp, yp;    // coordinate and position variables 
  var am, stx, sty;  // amplitude and step variables 
  var i, doc_width = 800, doc_height = 600; 
  if (ns6up) { 
    doc_width = self.innerWidth; 
    doc_height = self.innerHeight; 
  } else if (ie4up) { 
    doc_width = iecompattest().clientWidth; 
    doc_height = iecompattest().clientHeight; 
  } 
  dx = new Array(); 
  xp = new Array(); 
  yp = new Array(); 
  am = new Array(); 
  stx = new Array(); 
  sty = new Array(); 
  snowsrc=(snowsrc.indexOf("dynamicdrive.com")!=-1)? "http://2.bp.blogspot.com/-MsCdyoGtGdA/UX5gk72qNoI/AAAAAAAAAfQ/LaKTmUG-aJM/s1600/snow+falling+effect.gif" : snowsrc 
  for (i = 0; i < no; ++ i) {  
    dx[i] = 0;                        // set coordinate variables 
    xp[i] = Math.random()*(doc_width-50);  // set position variables 
    yp[i] = Math.random()*doc_height; 
    am[i] = Math.random()*20;         // set amplitude variables 
    stx[i] = 0.02 + Math.random()/10; // set step variables 
    sty[i] = 0.7 + Math.random();     // set step variables 
        if (ie4up||ns6up) { 
      if (i == 0) { 
        document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><a href=\"http://dynamicdrive.com\"><img src='"+snowsrc+"' border=\"0\"><\/a><\/div>"); 
      } else { 
        document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src='"+snowsrc+"' border=\"0\"><\/div>"); 
      } 
    } 
  } 
  function snowIE_NS6() {  // IE and NS6 main animation function 
    doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10; 
        doc_height=(window.innerHeight && snowdistance=="windowheight")? window.innerHeight : (ie4up && snowdistance=="windowheight")?  iecompattest().clientHeight : (ie4up && !window.opera && snowdistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight; 
    for (i = 0; i < no; ++ i) {  // iterate for every dot 
      yp[i] += sty[i]; 
      if (yp[i] > doc_height-50) { 
        xp[i] = Math.random()*(doc_width-am[i]-30); 
        yp[i] = 0; 
        stx[i] = 0.02 + Math.random()/10; 
        sty[i] = 0.7 + Math.random(); 
      } 
      dx[i] += stx[i]; 
      document.getElementById("dot"+i).style.top=yp[i]+"px"; 
      document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";  
    } 
    snowtimer=setTimeout("snowIE_NS6()", 10); 
  } 
    function hidesnow(){ 
        if (window.snowtimer) clearTimeout(snowtimer) 
        for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden" 
    } 
if (ie4up||ns6up){ 
    snowIE_NS6(); 
        if (hidesnowtime>0) 
        setTimeout("hidesnow()", hidesnowtime*1000) 
        } 
</script> - See more at: http://www.mybloggerwidgets.com/2013/04/add-snow-falling-effect-in-blogger.html#sthash.f73p6bHX.dpuf

Saturday, 21 December 2013

Add Floating Facebook Like Box For Blogger

STEP 1
1.  Go to Blogger Dashboard  ---> Template
2.  Please! download a copy of your template
3.  Now click on 
Edit HTML
4.  Use 
Ctrl+F to find </head>
5.  Then copy and paste just above/before it, this code:
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js' type='text/javascript'/>
6. Save your template.

STEP 2
1.  Now go to Layout--> click on "Add a gadget".
2.  Select "html/java script" and add the code given below and click save.
  <script type="text/javascript"> /*<![CDATA[*/ jQuery(document).ready(function() {jQuery(".abtlikebox").hover(function() {jQuery(this).stop().animate({right: "0"}, "medium");}, function() {jQuery(this).stop().animate({right: "-250"}, "medium");}, 500);}); /*]]>*/ </script> <style type="text/css"> .abtlikebox{background: url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKJYA16dgOe8rl3MpMePTXOR__o-aU4tgA8H8tv1EMbH_KtB8KaCl9BSOPljfVHd_0uyY0hs9toC2UJZnWgzJ8NMR7CSY71RffQpzhb1gBK-oVMinya6CXi-V71jVRsSaCTCRqu9m2Ckk/s320/fb1-right.png") no-repeat scroll left center transparent !important; float: right;height: 270px;padding: 0 5px 0 46px;width: 245px;z-index:  99999;position:fixed;right:-250px;top:20%;} .abtlikebox div{ padding: 0; margin-right:-8px; border:4px solid  #3b5998; background:#fafafa;} .abtlikebox span{bottom: 4px;font: 8px "lucida grande",tahoma,verdana,arial,sans-serif;position: absolute;right: 6px;text-align: right;z-index: 99999;} .abtlikebox span a{color: gray;text-decoration:none;} .abtlikebox span a:hover{text-decoration:underline;} } </style> <div class="abtlikebox" style="">     <div>     <iframe src="http://www.facebook.com/plugins/likebox.php?href=https://www.facebook.com/pages/Javapages4all/542211092478165&amp;width=245&amp;colorscheme=light&amp;show_faces=true&amp;border_color=white&amp;connections=9&amp;stream=false&amp;header=false&amp;height=270" scrolling="no" frameborder="0" scrolling="no" style="border: white; overflow: hidden; height: 270px; width: 245px;background:#fafafa;"></iframe><span>Widget by :<a href="http://www.bbloggertutorials.blogspot.com"> BBloggerTutorials</a></span>     </div> </div>
Note: Replace https://www.facebook.com/pages/Javapages4all/542211092478165 with your facebook page URL or user name.
Now you can see the result and be happy


String Reverse in Java

package raja.JavaPages4all;

public class Exam {

/**
* @param args
*/
public static void main(String[] args)
{
Stringreverse();
}

private static void Stringreverse()
{
String str="Raja is a Good Boy";
String reverse=null;

/*
* String reverse using StringBuffer
*/
reverse=new StringBuffer(str).reverse().toString();
System.out.println("String reverse using StringBuffer ="+reverse);

/*
* String reverse using StringBuilder
*/
reverse=new StringBuilder(str).reverse().toString();
System.out.println("String reverse using StringBuilder ="+reverse);

/*
* String reverse Without using API
*/
reverse="";
for(int i=str.length()-1;i>=0;i--)
{
reverse+=str.charAt(i);
}
System.out.println("String reverse Without using API ="+reverse);

System.out.println("reverseRecursively ="+reverseRecursively(str));
}

public static String reverseRecursively(String str)
{
/*
* base case to handle one char string and empty string
*/
if (str.length() < 2)
{
return str;
}

String res=reverseRecursively(str.substring(1)) + str.charAt(0);
return res;
}
}

Tuesday, 17 December 2013

Add Flying Twitter Bird in Blogger



Log in to blogger >Template > Edit HTML
Now press CTRL+F and find the following code

</body>

Now paste following code just after </body> 

<script src='https://sites.google.com/site/mmktricks/flyingtwitter.js' type='text/javascript'>
</script>
<script type='text/javascript'>
var twitterAccount = &quot;your twitter username&quot;;
var tweetThisText = &quot; <data:blog.pageTitle/> : <data:blog.url/> &quot;;
tripleflapInit();
</script>

You have to replace your twitter username with the highlighted color text. Save the template and see a nice animated flying twitter bird