【发布时间】:2020-01-13 08:33:29
【问题描述】:
当用户想要在对话框运行时返回上一个活动时,我希望它应该是单击(如 youtube)。在我的情况下,在第一次返回时单击进度对话框停止并显示一个空白页面,直到我的数据没有加载并在第二次后按时进入上一个活动....
我不希望这两次后按它会非常刺激用户使用应用程序。
有什么解决方案,因为我看了其他问题,但它不符合我的要求....
我在对话框中使用了以下代码:
progressDialog = new ProgressDialog(NextActivity.this );
progressDialog.setMessage("Loading....");
progressDialog.show();
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setCancelable(false);
完整代码:
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nextwhatsandroid_layout);
progressDialog = new ProgressDialog(NextActivity.this );
progressDialog.setMessage("Loading....");
progressDialog.show();
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// progressDialog.setCancelable(true);
progressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
//here, dismiss your dialog and finish your activity too
progressDialog.dismiss();
finish();
}
});
Toolbar toolbar = (Toolbar) findViewById(R.id. toolbar );
setSupportActionBar( toolbar );
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
Intent intent = getIntent();
String title = intent.getStringExtra("title");
String hello=intent.getStringExtra("hii");
String id = intent.getStringExtra("id");
Log.e("ashwini", String.valueOf(id));
getSupportActionBar().setTitle(title);
/*Create handle for the RetrofitInstance interface*/
DescriptService service = DescriptClientInstance.getRetrofitInstance().create(DescriptService.class);
Call<DescriptionModel> call = service.getAllPhotos(id);
call.enqueue(new Callback<DescriptionModel>() {
@Override
public void onResponse(Call<DescriptionModel> call, Response<DescriptionModel> response) {
progressDialog.dismiss();
DescriptList=response.body();
generateDataList(DescriptList);
}
@Override
public void onFailure(Call<DescriptionModel> call, Throwable t) {
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
}
});
}
private void generateDataList(DescriptionModel photoList) {
recyclerView = findViewById(R.id.recyclenext);
LinearLayoutManager manager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(manager);
recyclerView.setHasFixedSize(true);
adapter = new NextAndroidAdapter(getApplicationContext(),photoList);
recyclerView.setAdapter(adapter);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() ==android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
需要帮助..提前谢谢...
【问题讨论】:
-
你能在代码中分享你的问题的图像或屏幕吗?
-
progressDialog.show(); - 为什么你把这行加了两次?
-
@AkanshiSrivastava ..如果我不显示进度对话框,那么它将显示一个空白,直到我的数据数据加载..这对用户来说很不方便..progrees 对话框是必须的
-
@Wini 我明白显示进程对话框的重要性,但你为什么要调用 show() 方法两次?
-
嘿,我评论了一个...不是两个我在显示...只有一次我在显示...@AkanshiSrivastava