내 응용 프로그램이 웹에서 다운로드하는 데이터를 저장할 위치를 사용자가 선택할 수 있도록 응용 프로그램 시작 부분에 경고 대화 상자를 만듭니다. 지금 달성하고 싶은 것은 내부/외부 저장소의 크기에 따라 선택 항목 중 하나를 설정하려고합니다.Android가 경고 대화 상자에서 선택한 항목을 설정합니다.
@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();
}
내가 달성하고자하는 또 다른 것은 나는 그가 어떤 항목을 선택하지 않은 경우 경고 대화 상자를 닫습니다 사용자를 방지 할 수있는 방법 : 여기에 내가 대화 상자를 만드는 데 사용하고 코드입니다. 뒤로 버튼을 누르거나 확인 버튼을 클릭 할 때 대화 상자를 닫고 싶지 않습니다. 모든 아이디어/제안/도움을 환영합니다!