BÀI 55 - LOAD DỮ LIỆU HIỂN THỊ PROGRESS BAR TRONG ANDROID
Trước tiên tạo một xml chứa progressBar như sau:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progress_bar"
android:indeterminate="true" // Đặt progress nằm ở vị trí bất kì
android:layout_width="40dp"
android:layout_height="wrap_content"/>
</LinearLayout>
Gọi layout progressBar vừa tạo vào file java.
View footerView; // Biến toàn cục
// Ánh xạ
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
footerView = inflater.inflate(R.layout.progresbar, null);
Để bật progress bar, gọi hàm:
listView.addFooterView(footerView);
Để tắt thì gọi đoạn code
listView.removeFooterView(footerView);
Kết quả là một progress bar sẽ xuất hiện bên dưới một listView, thích hợp cho ứng dụng load thêm dữ liệu.