Tôi đang tạo một Hộp thoại cảnh báo ở đầu ứng dụng để cho phép người dùng chọn nơi lưu trữ dữ liệu mà ứng dụng của tôi tải xuống từ web. Thứ mà tôi muốn đạt được bây giờ phụ thuộc vào kích thước của Internal/External Storage tôi muốn thiết lập một trong các mục. Đây là mã mà tôi đang sử dụng để tạo hộp thoại:Android đặt mục đã chọn trong hộp thoại cảnh báo
@SuppressWarnings("static-access")
public void createDialog(){
final CharSequence[] items = {"Phone Memory - "+memorysize+" free space", "SD Card - "+megAvailable+" MB free space"};
final int userId = rpc.getUserId(this);
final String servername = rpc.getCurrentServerName(this);
SharedPreferences stampiiSettings = PreferenceManager.getDefaultSharedPreferences(MyCollectionList.this);
final SharedPreferences.Editor editor = stampiiSettings.edit();
AlertDialog.Builder builder = new AlertDialog.Builder(this.getParent());
builder.setTitle("Select Storage Path");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if(item == 0){
rpc.createFoldersInInternalStorage(servername, userId, MyCollectionList.this);
Toast.makeText(getApplicationContext(), "Selected Storage Path : Phone Memory", Toast.LENGTH_SHORT).show();
editor.putInt("storagePath", 1);
editor.commit();
} else if (item == 1){
rpc.createFoldersInExternalStorage(servername, userId, MyCollectionList.this);
Toast.makeText(getApplicationContext(), "Selected Storage Path : SD Card", Toast.LENGTH_SHORT).show();
editor.putInt("storagePath", 2);
editor.commit();
}
}});
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mHandlerUpdateUi.post(mUpdateUpdateUi); // update UI
}
});
AlertDialog alert = builder.show();
}
Và một điều khác mà tôi muốn đạt được, làm cách nào để ngăn người dùng đóng Hộp thoại cảnh báo nếu không chọn bất kỳ mục nào. Tôi không muốn đóng hộp thoại khi nhấn nút quay lại hoặc khi bạn nhấp vào nút OK. Bất kỳ ý tưởng/gợi ý/trợ giúp được hoan nghênh!