Miyerkules, Enero 23, 2013

Android Database Programming basics (FIRST STEP)

 
First, create an Android project, throw in an Activity class during creation. Compose the UI, the res/layout/main.xml might look like this
 
<?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"
    >
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/todoedit"
        android:layout_weight="0"
    />
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="10"
    >
        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="I have nothing"
            android:id="@+id/tododisplay"
        />
    </ScrollView>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Add item"
        android:id="@+id/btnadd"
        android:onClick="recAdd"
        android:layout_weight="0"
/>
</LinearLayout>
The TextView component is embedded in a ScrollView component so that we can scroll through the contents of the TextView. The ScrollView acts like a viewport. We also used weight property of the layout so that our viewport is given the most screen real-estate. See the note on how to use weights to maximize screen space
The Button's onClick property is a method called recAdd which we need to define inside the Activity class.
 

Walang komento:

Mag-post ng isang Komento