1
내 응용 프로그램에서 파일을 다운로드하기위한 진행 대화 상자가 표시되지만 다운로드를 취소해야하는 경우 다시 버튼을 눌러야 알리미가 표시됩니다 대화 상자에는 두 개의 버튼이 있습니다. 문제는 경고 대화 상자의 단추를 두 번 눌러야한다는 것입니다. 그러면 경고 대화 상자 만 닫힙니다. 그것을위한 해결책을 제안 해주세요. 여기AlertDialog 버튼을 두 번 클릭해야합니다.
는
@Override
protected Dialog onCreateDialog(int id)
{
switch (id)
{
case progress_bar_type:
pDialog = new ProgressDialog(this);
pDialog.setMessage("Downloading file. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.show();
pDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_BACK){
running = false;
/*Intent intent = new Intent(context, NewDialog.class);
startActivity(intent);*/
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setIcon(R.drawable.ic_launcher);
alertDialog.setTitle("Ariisto");
alertDialog.setMessage("Do you Want to Cancel the Download ?");
alertDialog.setCancelable(true);
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
File externalFile = new File(Environment.getExternalStorageDirectory(),"downloadedfile.pdf");
externalFile.delete();
pDialog.dismiss();
running = false;
Log.d("External File", "DELETED");
pDialog.setProgress(0);
count = 2;
}
});
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
new DownloadFileFromURL().execute(file_url);
running = true;
count = 0;
}
});
AlertDialog alert = alertDialog.create();
alert.show();
}
return false;
}
});
안녕 Egor .. 그러나 제안에 대한 감사합니다 onKeyDown() setOnKeyListener있는 onKey() 표시 같이 무시할 수 없습니다. 위의 스 니펫에 대해 onKeyDown()에 대한 코드 스 니펫을 표시 할 수 있습니까? 아니면 다른 유용한 튜토리얼이나 도움이 될 수있는 링크로 리디렉션됩니다. 감사. –
또한 activity의 onKeyDown() 메서드를 재정의하려고했지만 여전히 동일한 결과를 제공합니다. –
@NitinBathija, 예, 저는 Activity의 onKeyDown() 메서드를 의미했습니다. – Egor