customdialog - Android Custom Dialog not Showing -
i want show simple custom dialog. starters wanted add text view , see if dialog show.
this xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <textview android:id="@+id/tvpreview" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/instructions"></textview> </linearlayout> this code oncreatedialog function:
@override protected dialog oncreatedialog(int id) { final dialog dialog = new dialog(this); dialog.setcontentview(r.layout.predialog); dialog.settitle("tests of dialog"); return dialog; } when user (me) presses menu item use code:
public void diagtests(){ showdialog(0); } what happens screen obscures dialog doesn't show.
does have idea of i'm doing wrong?
pd: in case there no errors or warnings of kind.
thanks help
you try approach. create custom dialog class (this example of class, can use want):
/** class must extends dialog */ /** implement onclicklistener dismiss dialog when ok button pressed */ public class dialogwithselect extends dialog implements onclicklistener { private string _text; button okbutton; button cancelbutton; /** * progressdialog shown during loading process */ private progressdialog mydialog; public dialogwithselect getdialog() { return this; } public string gettext() { return this._text; } public dialogwithselect(context context) { super(context); mydialog = new progressdialog(this.getcontext()); mydialog.setmessage("exporting file..."); /** 'window.feature_no_title' - used hide title */ requestwindowfeature(window.feature_no_title); /** design dialog in main.xml file */ setcontentview(r.layout.dialog_with_select_box); final spinner hubspinner = (spinner) findviewbyid(r.id.spinnerselectformat); arrayadapter adapter = arrayadapter.createfromresource( this.getcontext(), r.array.spinner , android.r.layout.simple_spinner_item); adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); hubspinner.setadapter(adapter); okbutton = (button) findviewbyid(r.id.okbutton); cancelbutton = (button) findviewbyid(r.id.cancelbutton); okbutton.setonclicklistener(new view.onclicklistener(){ public void onclick(view v) { //whatever } }); cancelbutton.setonclicklistener(new view.onclicklistener(){ public void onclick(view v) { //get text texstring paint on canvas getdialog().hide(); } } ); } define dialog on class going used:
final dialogwithselect dialog = new dialogwithselect(getcontext()); dialog.settitle(r.string.dialogselectboxtext); and launch in click event:
dialog.show();
Comments
Post a Comment