How to make textview stay visible with softkeyboard

If you have a textview that spans a few lines, but have buttons or something else below the textview that you would like to be shown, you can have the textview object be resized automatically to make room for Android’s softkeyboard. To do this, simply add one line to your AndroidManifest.xml file.

android:windowSoftInputMode="adjustResize"

This line of code should go inside of the

<activity
android:name="SomeActivityName"
android:windowSoftInputMode="adjustResize" >
</activity>

How to link text in Android

One of the weirdest things I stumbled across was the ability to hyperlink text in the Android environment.  Here is how to hyperlink text and then make it clickable.

TextView txtTheLink = (TextView)findViewById(R.id.txtTheLink); // Grab our textview/whatever with the HTML
txtTheLink.setText(Html.fromHtml("<a href=\"https://www.vooba.net\">Go to Vooba!</a>")); // Convert from HTML to remove the HTML tag>
txtLinks.setMovementMethod(LinkMovementMethod.getInstance()); // Activate the link

Hope this helps!

PHP Arrays in JAVA

Going from PHP to Java is a step backwards when dealing with arrays (imo).  One of the more beneficial things that you can do with a PHP array is define keys.  For example I can do something like:

$myList = array("oranges"=>15, "apples"=>25);

Then I can access how many oranges I have by going echo $myList[“oranges”];

To do something like this in JAVA is a bit different than just defining a normal array. In JAVA you need to use a HashMap:

HashMap<String,Integer> myList = new HashMap<String,Integer>();
myList.put("oranges", 15);
myList.put("apples", 25);
If you need to store two strings, then change the object type (I.e. HashMap<String,String>).
To get the value, simply use the get method.

myList.get("oranges");

How to use Unix Timestamp with Java

You can use a unix timestamp in java wit the following code:

import java.util.Date;
String TimeStamp = "1324716371";
Date time=new Date((long)TimeStamp*1000);

Now, timestamp doesn’t have to be a string, however in many of your projects you may have the value in that format. In this case, we convert it to a long (integer is too small), and then multiply it by 1000 since Java uses milliseconds.

How to remove the title or “Application Name” bar

To remove the bar that appears at the top of your activity, modify your AndroidManifest.xml document.  Foreach activity, add the line:

android:theme="@android:style/ThemeNoTitleBar.Fullscreen"

Making the result look like:

<activity android:name=".MainActivity"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.NoTitleBar.Fullscreen">