简体   繁体   English

关闭对话框后如何从对话框中获取数据?

[英]How to get data from dialog after i dismiss it?

I have tried to get data from a dialog into a textview but i get the error that the app can t see the textview, because textview is behind dialog... after i click on button this will appear我试图从对话框中获取数据到文本视图中,但我收到应用程序无法看到文本视图的错误,因为文本视图在对话框后面......单击按钮后,这将出现

backpackDialog = new Dialog(MainActivity.this);
backpackDialog.setTitle("Backpack"); 
backpackDialog.setContentView(R.layout.backpack_layout); 
window = backpackDialog.getWindow(); 
lp.copyFrom(window.getAttributes()); 
lp.width = WindowManager.LayoutParams.MATCH_PARENT; 
lp.height = WindowManager.LayoutParams.WRAP_CONTENT; 
window.setAttributes(lp); 
backpackDialog.show(); 

// and after i click to dissmis the dialog...
useItemButton.setOnClickListener(new View.OnClickListener() 
{ @Override public void onClick(View view) 
  {  
     // here is the problem...
     intPlayerHealth = intPlayerHealth + 20;
     ->playerHealthText.setText(intPlayerHealth);<-
     backpackDialog.dismiss();
  } 
});

how can i go after i dismiss the dialog to restart activity or something like that to refresh my main activity layout so that way i can get the new value for my textView, and also to not get that error of not being able to see textView, thank you我如何关闭对话框以重新启动活动或类似的东西来刷新我的主要活动布局,这样我就可以获得我的 textView 的新值,并且不会出现无法看到 textView 的错误,谢谢你

It's simple written in official documentation 官方文档里写的很简单

@Override
public void onDismiss(@NonNull DialogInterface dialog) {
    // here is the problem...
    // You can write you action here
    super.onDismiss(dialog);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM