Tuesday, November 30, 2010

Marquee Attributes

This has absolutely nothing to do with Android or Java.

I had a text marquee announcement news thingy on my company website, and I didn't want to lose the code because it took me a full day to figure out how to use marquee attributes.

<marquee behavior="scroll" direction="left" scollamount="1" onmouseover="this.stop();" onmouseout="this.start();"></marquee>

Friday, November 26, 2010

Setting up Android Development Environment with Eclipse

I've done set up a fifth computer with the Android Dev environment and every time it's a gorram struggle. I hate setting up workstations! So here I am, finally conceding to the idea that there will never be a last and final time for the most tedious, time consuming, and confusing chores.

1) Download Eclipse IDE for Java Developers 3.5 (Galileo). The newer version 3.6 Helios is not supported by android. Galileo comes as a zip file, no install necessary. Unzip somewhere you will remember, and make shortcuts to your desktop/task bar/whatever.
http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/galileor

2) Download JDK/JRE v.6 (or the new v.7). Follow the install. You will need a login username and password for Sun Microsystems. (*Optional: After install, find the jdk folder, and copy the "jre" file into your eclipse folder. I don't know if this is the correct way to do this, but it works for me. Particularly useful if you downloaded the Android SDK as a zip rather than the installer.)
http://www.oracle.com/technetwork/java/javase/downloads/index.html

3) Download Android SDK. This can also come as a zip file but also includes an installer which I will recommend, because the installer will "link" the Android SDK to the JDK. Whatever that means. But because of this linking thing, the JDK has to be fully installed first in order to run.
http://developer.android.com/sdk/index.html

4) Add SDK Platform. After the installer from step 3 finishes, start the SDK program. Start checking off stuff to add. You need at least ONE platform to begin developing in android. You will need to download all the versions you plan on testing on. Be sure to add packages in small groups, if you try to do it all at once it crashes or never finishes.

5) "Download"/Install/Configure ADT plugin. Finish downloading the SDK in step 4 before attempting this. Adding the ADT to Eclipse requires use of the "Adding new software" option from the Help menu. Its awful and feels wrong. Instructions at the link below. Be sure to follow the steps for downloading AND configuring the ADT plugin!



6) Create an AVD (Android Virtual Device.)  This is the emulator. I set the target to Android 2.2 - API Level 8, and the skin to WVGA854
http://developer.android.com/guide/developing/tools/avd.html#creating

Resources:
http://developer.android.com/sdk/requirements.html
http://developer.android.com/sdk/installing.html

Thursday, November 18, 2010

Adding xml Layout to an Existing xml Layout Dynamically

So some background information is needed for this tutorial. My project requires many many many screens. It's incredibly difficult to keep track of all these for development purposes, and on top of that it makes load time on the phone mind-bogglingly slow. So I am trying to create generic "blank" screens to use and reuse for my applications. In this particular example, I have created a generic list screen with a TextView "title" and a blank ListView. I already know that I can programically change the row styling, data entries, the text in the title, etc etc. But I needed to add a row of buttons to the bottom. So I created a simple xml layout with some buttons inside a horizontal linear layout. This is where I hit the snag. I assumed it would be simple to just say mainlayout.addView(extrabuttonslayout); 


I was wrong.

So after three or four days of searching, attempting, failing... (Yeah I know I'm slow) I magically discovered four magical lines of text that allow me to make all my wildest dreams come true. At least for now.

So here's how I did it:

main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:id="@+id/LinearLayout_listview">
<TextView android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="title" android:id="@+id/TextView_Title"
android:padding="5px" android:textSize="20px" />
<ListView android:layout_height="wrap_content" android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_weight="1" />
<FrameLayout android:layout_height="wrap_content"
android:id="@+id/FrameLayout_listview" android:layout_width="fill_parent" />
</LinearLayout>


extrabuttonlayout.xml

<LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent"
android:gravity="center" android:id="@+id/LinearLayout_er">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Search"
android:minWidth="100px" android:id="@+id/btnEmergencyResponse_Search"></Button>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Exit"
android:minWidth="100px" android:id="@+id/btnEmergencyResponse_Exit"></Button>
</LinearLayout>

and finally the oh so dynamic MainActivity.java (I only included the part where I dynamically add a view, for info on how to dynamically populate a listview, or handle click evens, see my other entries.) Basically here we are setting our layout to be a "view" and then adding the view to the main layout. Silly me, I already thought it was a view...

public class MainActivity extends ListActivity {

LayoutInflater linflater;
LinearLayout llList;
LinearLayout llER;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

//trying to add view to listview.xml
llList = (LinearLayout) findViewById(R.id.LinearLayout_listview);
                linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View myView = linflater.inflate(R.layout.extrabuttonlayout, null);
                llList.addView(myView);


}
}