Thực hành sử dụng RecyclerView trong android java p3

Update: Dùng cardview để trình bày các item Bạn thay thế layout của custom_item_layout.xml bằng layout dưới đây. Cơ bản là có 1 LinearLayout bọc ngoài rồi cho cái cardView vào trong để bao gói, bên trong đó tiếp tục cho 1 cái layout để trình bày các phần tử con. <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout […]

Thực hành sử dụng RecyclerView trong android java p2

Phần này: Cải tiến thêm nút bấm mỗi khi bấm nút sẽ thêm 1 dòng trong danh sách và tự động hiển thị lên danh sách Bước 1: Trong layout của main activity thêm nút FloatButton:    <com.google.android.material.floatingactionbutton.FloatingActionButton        android:layout_width=”wrap_content”        android:layout_height=”wrap_content”        app:layout_constraintBottom_toBottomOf=”parent”        app:layout_constraintRight_toRightOf=”parent”        android:id=”@+id/fab_01″        android:src=”@android:drawable/ic_input_add”        android:backgroundTint=”#FF9800″        /> – […]

DatePicker trong android java

Hướng dẫn dùng DatePicker gắn trực tiếp trên layout của activity Bước 1: Trên layout thả vào 1 view là DatePicker <DatePicker android:id=”@+id/dpk_01″ android:layout_width=”316dp” android:layout_height=”wrap_content” android:layout_gravity=”center” /> Bước 2: Viết code java trong activity DatePicker datePicker = findViewById(R.id.dpk_01); // sử dụng đối tượng lịch để cài đặt Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis( System.currentTimeMillis() ); // […]

DatePicker Dialog trong android java

Bài viết này sử dụng DatePicker dạng Dialog khác với DatePicker gắn trên layout https://zezo.dev/view/datepicker-trong-android-java Trên layout sẽ thêm 1 textview, khi bấm vào textview thì hiển thị dialog chọn ngày tháng, khi chọn ngày tháng trên dialog thì sẽ gán lại ngày tháng vào textview Bước 1: Thêm textview vào layout của activity <TextView android:id=”@+id/tv01″ […]

TimePickerDialog trong android java

Demo sử dụng TimePickerDialog để chọn thời gian trong android java Bạn nên tạo 1 Project mới để thử nghiệm Bước 1: Trong layout bạn tạo 1 cái textview để chọn thời gian <TextView android:id=”@+id/tv_time” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Thời gian” android:textSize=”30dp” android:textColor=”#FF5722″ android:layout_margin=”30dp” /> Bước 2: Thực hiện viết code java theo thứ tự sau TextView tv […]

Tạo đồng hồ đếm ngược thời gian trong android java

Bước 1: Tạo 1 project mới và tạo 1 textview trong layout activity <TextView android:id=”@+id/tv01″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> Bạn tự căn chỉnh textview cho phù hợp Bước 2: Trong code java của activity, bạn viết code sau để thực hiện đếm ngược TextView tv01 =findViewById(R.id.tv01); // ánh xạ view // tạo mới 1 đối tượng […]

Tạo Toast tùy chỉnh trong android java

Bước 1: Tạo 1 file layout cho cái Toast Chú ý đặt id cho thẻ LinearLayout là toast_root_layout còn các view con cái nào muốn gán giá trị thì đặt ID <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”horizontal” android:layout_width=”match_parent” android:layout_height=”match_parent” android:background=”#FFEB3B” android:id=”@+id/toast_root_layout” android:padding=”30dp” > <ImageView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:src=”@android:drawable/ic_delete”/> <TextView android:id=”@+id/tv_toast_content” android:layout_width=”0dp” android:layout_weight=”1″ android:layout_height=”wrap_content” android:text=”Nội dung toast” android:textColor=”#FF5722″ android:textSize=”20dp”/> […]

Mẹo học lý thuyết 600 câu hỏi luật Giao thông đường bộ

1. Soi đáp án nhanh để chọn – Đáp án “Bị nghiêm cấm” luôn chọn là đúng – Đáp án có từ: “Giảm tốc độ” và có từ “bên phải” thì chọn đáp án này – Đáp án có từ: “Quan sát” chọn đáp án nào có nội dung dài nhất – Đáp án có từ: “Không được” thì […]

Hướng dẫn code upload file trong php bằng ajax có progress

Bước 1: Chuẩn bị cấu trúc các file và thư mục như sau ├── index.html ├── upload.php ├── uploads/ ├── js/ │ └── jquery.min.js ├── css/ │ └── style.css └── images/ – File index.html để hiển thị form chọn file và hiển thị tiến trình upload – File upload.php để xử lý lưu trữ file […]

Hướng dẫn lấy định vị (GPS)

Tài liệu tham khảo định vị: https://developer.android.com/training/location Bước 1: Copy permission cho vào Mainifest: <uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION” /> <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” /> <uses-permission android:name=”android.permission.INTERNET” /> Bước 2: Khai báo đối tượng để nhận trạng thái khi hộp thoại cấp quyền đóng lại: Code này để ở phạm vi class, để bên ngoài hàm onCreate nhé. ActivityResultLauncher<String[]> locationPermissionRequest = registerForActivityResult(new ActivityResultContracts […]