Skip to main content

Bài 3 - Ứng dụng đầu tiên ( Nhập vào 2 số và tính tổng)

Hướng dẫn bởi StudingCoding
Hôm nay mình sẽ hướng dẫn các bạn làm 1 app đơn giản android trên Eclipse
Ứng dụng đầu tiên - Nhập vào 2 số tính tổng
---------------
1. Hướng dẫn thực hiện
[QUOTE]
Bước 1: Cài đặt và cấu hình Eclipse ( các bạn có thể xem lại ở bài viết trước)
Bước 2: Khởi động Eclip vào tạo 1 project
Mình sử dụng máy ảo Gennymotion ( bạn có thể vào xem hướng dẫn cài đặt máy ảo này)
Bước 3: Sau khi tạo xong project ta bắt đầu viết ứng dụng
+ Vào layout để thiết kế giao diện cho ứng dụng trước.
Giao diện gồm có 2 cái nhãn để hiện " Nhập a" "nhập b"
và tương ứng 2 o Edittext để nhập dữ liệu
+ 1 button để xuất kết quả

Các control bạn có thể kéo thả vào hoặc vào file code để code
Đã xong phần giao diện ( các bạn nhớ lưu lại nhé)
Kết quả sẽ xuất ra dưới dạng thông báo nhé!
+ Vào file xử lý để code
      - Ánh xạ các control bên giao diện qua file xử lý
    - xử lý
---> đã code xong
Bước 4: chạy ứng dụng
Vừa chạy ứng dụng báo lỗi " nhập dữ liệu"!
Kết quả k tinh được ( do k có dữ liệu)
đã hết lỗi[/QUOTE]
2.  Demo kết quả:
3. Source code
Code giao diện:
[ code]<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/TableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TableRow>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nhập a" />
        >
        <EditText
            android:id="@+id/edta"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|top"
            android:ems="10"
            android:inputType="number" >

            <requestFocus />
        </EditText>
    </TableRow>

    <TableRow>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nhập b" />
        >
        <EditText
        android:id="@+id/edtb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|top"
        android:ems="10"
        android:inputType="number" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/btnTinh"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:text="Tính" />

    </TableRow>

</TableLayout>[ /code]
Xử lý:
[ code]<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/TableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TableRow>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nhập a" />
        >
        <EditText
            android:id="@+id/edta"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|top"
            android:ems="10"
            android:inputType="number" >

            <requestFocus />
        </EditText>
    </TableRow>

    <TableRow>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nhập b" />
        >
        <EditText
        android:id="@+id/edtb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|top"
        android:ems="10"
        android:inputType="number" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/btnTinh"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:text="Tính" />

    </TableRow>

</TableLayout>[ /code]
Lưu ý: Bài viết bản quyền của StudingCoding

Comments

Popular posts from this blog

Mẹo và giải thuật C# dành cho người mới bắt đầu

Với nội dung kiến thức cơ bản nhất. Gồm 31 trang với những nội dung:  1. Kết nối CSDL SQL  -----------How to Create SQL Connection in C# 2. Đọc ghi file text với C#  -----------How to Write Text to a Txt File in C# -----------How to Read Text from a TXT File 3. Xóa Cookie C# -----------How to Delete Cookie Using C# 4. Gửi main sử dụng tài khoàn Gmail với C# -----------How to Send Email Using Your Gmail Account in C# 5. Kiểm tra ký tự nhập vào từ bàn  phím -----------How to Check If a Key Is Pressed In C# 6. Đổi tên file trong C# -----------How to Rename a File Using C# 7. Vô hiệu hóa chuột trong ô textbox C# -----------How to Disable Right Click in C# Textbox 8. Chọn tất cả trong listbox -----------How to Add Select All Button or Checkbox in CheckedListBox 9. Tạo mới thư mục bằng C# -----------How to Create a New Folder Using C# 10. Lấy các tiến trình đang chạy C# ----------- How to Get List of All the Running  Processes in C# 11. Tả...

Tài liệu hướng dẫn lập trình game với cocos2d-x

Thực hiện bởi: Admin Page Học Lập Trình https://www.facebook.com/hoclaptrinh.it Nội dung Phần 1: Cơ bản về cocos2d-x và khái niệm trong game Bài 1. Giới thiệu về Cocos2d-x Bài 2. Cài đặt Cocos2d-x Bài 3. Tạo ứng dụng đầu tiên Hello world Bài 4. Khái niệm Sprite và SpriteSheet Bài 5. Basic Action Bài 6. EFFECT & MUSIC Bài 7. Lập trình sự kiện Touch Bài 8. Cách tạo menu đơn giản (Cocos2d-x căn bản) Bài 9 . Hướng dẫn làm 1 game đơn giản bằng Cocos2d-x Phần 2: Vật lý trong game Bài 1 - Physics là gì, tại sao phải thêm Physics? ------------------------------Bắt đầu nội dung ------------------------------ “Write Once, Run Anywhere” (WORA)” Phần 1. Cơ bản về cocos2d-x và khái niệm trong game Bài 1. Giới thiệu về Cocos2d-x 1. Sơ lược về cocos2d-x 2. Vì sao chúng ta nên chọn cocos2d-x 3. Các kiến thức cần có 1. Sơ lược về cocos2d-x Là 1 Engine hỗ trợ lập trình Game đa nền tảng Xuất xứ từ trung quốc Hỗ trợ ngôn ngữ C+...

Bài tập thuật toán C/C++ Và Tuyển tập đề thi olympic

Gồm: +  Các thuật toán của Lê Minh Hoàng + Tuyển tập các đề thi olympic tin học sinh viên Link down: Tại đây