kiem tien, kiem tien online, kiem tien truc tuyen, kiem tien tren mang
Thứ Tư, 5 tháng 3, 2014

Trước tiên hãy đảm bảo rằng Eclipse của bạn đã được Plug-In thư viện Android thành công 

Một ứng dụng Android cơ bản gồm các thành phần sau:



Trong đó, chúng ta phải thiết lập và code các file sau (bạn có thể copy và patse vào đúng vị trí):

1- Res \ layout (main.xml): 

<?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:id="@+id/edit_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/edit_hint" />
     
        <TextView android:id="@+id/text_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/text_color"
            android:textSize="28px"
            android:typeface="monospace" />
</LinearLayout>

2- Res \ values:

 + string.xml (thiết lập các chuỗi ký tự):

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, Example!</string>
    <string name="app_name">Loi chao: </string>
    <string name="edit_hint">Nhap vao ten cua ban!</string>
 </resources>

 + color.xml (thiết lập màu chữ):

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="text_color">#ff3300</color>
</resources>


3- src \ [Package của bạn] \ [class chính của bạn] (chứa code xử lý) :

package txt.B.Nhap;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.EditText;
import android.widget.TextView;
public class NhapSOActivity extends Activity {
/** Called when the activity is first created. */

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Thiet lap giao dien lay tu file main.xml
setContentView(R.layout.main);
//Lay ve cac thanh phan trong main.xml thong qua id
final EditText edit = (EditText)
findViewById(R.id.edit_text);
final TextView text = (TextView)
findViewById(R.id.text_view);
//Xu ly cho su kien an nut giua tren dien thoai
edit.setOnKeyListener(
new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
String chao="Chao ban "+edit.getText().toString();
text.setText(chao);
edit.setText("");
return true;
}
else {
return false;
}
}
});
}
}

*** Chú ý: Bạn cần để ý tên Project mà bạn tạo để thay đổi code cho chuẩn.

>> Kết quả khi thực thi ứng dụng:


05 Mar 2014

0 nhận xét:

Đăng nhận xét

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

domain, domain name, premium domain name for sales

Bài đăng phổ biến