ANDROID java course - Thắng STAR❤️

ANDROID java course


 

Xử lí đa luồng

Kế thừa class Thread: override hàm:

+ run: nội dung cần xử lý

+ start: bắt đầu chạy

+ setPriority: set độ ưu tiên

+…

Ẩn title và full screen

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
       
WindowManager.LayoutParams.FLAG_FULLSCREEN);

 

ActionBar actionBar = getSupportActionBar();
actionBar.hide();

 

Action bar:

-        Thêm item trong action bar:

1.     Khai báo app, import cái resauto để nó tự động thay đổi phù hợp theo đúng kích thước màn hình

2.     Thêm 1 item có id là add_item

+ icon là đường dẫn hình item trong drawable

+ title: tên chính của item

+ showAsAction: luôn hiện, ẩn,…

 

xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/add_item" android:icon="@drawable/add" android:title="New" app:showAsAction="always"></item>

 

Background button không thể thay đổi, hãy kiểm tra file themes.xml (trong file theme) đã để:

Theme.AppCompat.Light.NoActionBar

 

Phím tắt:

Shift 2 lần để di chuyển giữa các tab nhanh hơn

 

Cách tạo toolbar:

1.     Chuyển sang noActionbar

2.     Tạo toolbar trong xml chính

3.     Trỏ id đến toolbar vừa tạo

4.     Tạo menu trong res

5.     Tạo file toolbar xml trong menu vừa tạo

6.     Thêm các item cho toolbar vừa tạo

7.     Set toolbar vừa tạo cho activity:

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater()
;
   
menuInflater.inflate(R.menu.toolbar_main, menu);
    return true;
}

8.     Set actionbar trong activity bằng:

setSupportActionBar

 

Cách debug:

1.     Viết hàm Log.i và biến cần xem giá trị

2.     Đặt breakpoint

3.     Nhấp vào icon debug(hình con bọ): bắt đầu debug

4.     Nhấp vào để step over

5.     Quan sát các giá trị biến.

 

Tạo số ngẫu nhiên sử dụng đa luồng

(ít tốn kém hơn so với việc sử dụng lớp java.util.Random):

ThreadLocalRandom.current().nextInt(min, max+1)

 

 

Adapter: set dữ liệu, liên kết các view. => tạo thành list view, …

LayoutInflater: Chuyển đổi từ layout sang kiểu View

 

gridView: view theo dạng khối

listView: view theo dạng danh sách

ViewPager: view theo dạng từng page.

ð  gridView, listView: kế thừa từ baseAdapter

ð  ViewPager: kế thừa từ PagerAdapter, và cần override destroyItem và instantiateItem.

 

Chạy action khi có tin nhắn đến:

1.     Đăng kí và cấp quyền SMS trong manifest

<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>

2.     Tạo 1 class action khi có tin nhắn đến extend từ BroadcastReceiver

3.     Tạo 1 receiver trong manifest. SỰ kiện khi có tin nhắn mới

<receiver android:name=".SMSReceiver"
   
android:exported="true">
    <intent-filter>
        <action
android:name="android.provider.Telephony.SMS_RECEIVED"></action>
    </intent-filter>
</receiver>

 

 

 

Cách đọc tin nhắn:

1.     Tạo 1 bundle để get được dữ liệu từ intent trong onReceive

2.     Get pdus trong bundle và chuyển thành object get pdus trong bundle

3.     Dùng for để duyệt hết các object

4.     Tạo SmsMessage lấy dữ liệu từ pdus

 

Kết nối firebase =>

1.     Lấy mã SHA1:

2.    

3.     Add các thư viện theo hướng dẫn trong web firebase

4.     Create FireBaseDatabase, DatabaseRefenrece

5.     Từ databaseReference ta có thể truy xuất đến file con bằng: child, set giá trị: setValue.

databaseReference.child("users").child(“name”).setValue(“Thắng đẹp trai!”);

 

 

Get dữ liệu trong firebase

Child đến key có value là 1 object, sau đó duyệt mảng

! class user trong ví dụ phải có 2 contractor:  1 là rỗng, 2 là contractor truyền value

 

Lấy data up lên list view:

1.     Tạo 1 layout adapter

2.     Tạo adapter kế thừa từ base adapter

3.     setAdapter cho listview

4.     thêm sự kiện: addChild

firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference().child("user");

databaseReference.addChildEventListener(this);

5.     add dữ liệu vào array của bạn

Mọi Bài Đăng Đều Được Viết Bởi Tác Giả ADMIN NHT Blog, Vui Lòng Ghi Nguồn ADMIN NHT Blog Khi Copy Bài Đăng Từ Trang Này!

Admin: Thắng Star

[...] Sống đẹp là không phân biệt giàu nghèo mà cảm nhận bằng cách sống và cách chơi của nhau. Beautiful living is no differentiate between rich and poor that feel by living and playing each other.

Phản Hồi Độc Giả


Biểu Tượng Cảm XúcBiểu Tượng Cảm Xúc