I have created custom dialog and I want to close it on Cancel button click. I searched on google, most of the people are using Dialog or AlertDialog but I am not using anything like that. This is my TextDialogActivity
which is loading on button click in my app. From MainActivity
I am just rendering another activity as custom dialog. When I click Save
button on the dialog I want to access data in parent activity, which is stored in a variable textData
in child activity.
public class TextDialogActivity extends AppCompatActivity {
TabHost tabHost;
private static final int FILE_SELECT_CODE = 0;
private String textData;
private Button browse;
private Button cancel_button1;
private Button cancel_button2;
private TextView text_preview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text_dialog_layout);
browse = findViewById(R.id.browse_file_button);
text_preview = findViewById(R.id.text_preview);
cancel_button1 = findViewById(R.id.cancel_button);
cancel_button2 = findViewById(R.id.cancel_button2);
tabHost = findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec spec=tabHost.newTabSpec("tag1");
spec.setContent(R.id.encode_dialog_text_tab);
spec.setIndicator("Edit Text");
tabHost.addTab(spec);
spec=tabHost.newTabSpec("tag2");
spec.setContent(R.id.encode_dialog_browse_tab);
spec.setIndicator("Browse");
tabHost.addTab(spec);
browse.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showFileChooser();
}
});
cancel_button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// close dialog
}
});
cancel_button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// close dialog
}
});
}
}
I added @style/Theme.AppCompat.Dialog
to my AndroidManifest.xml to make my dialog.
<activity
android:name=".activity.TextDialogActivity"
android:theme="@style/Theme.AppCompat.Dialog"
android:label="Secret Message">
</activity>
This is the screenshot.