android - Open Dialog bound to another Context -
i have activity (documentactivity.java) bounded context dialog (documents_link_onclick_dialog.xml). on dialog want open when click on button dialog (documents_link_editlink.xml) time dialog should have activity (urlactivity.java). tried these 4, none of these worked.
// try 1 new urlactivity().showdialog(r.layout.documents_link_editlink); // try 2 startactivity(new intent(this, urlactivity.class)); // try 3 dialog.setcontentview(r.layout.documents_link_editlink); dialog.show(); // try 4 final dialog dialog2 = new dilog(urlacitivty.this); dialog2.show()
what doing wrong? hope can me :)
here find relevant classes:
androidmanifest.xml
<activity android:name=".documents.urlactivity" android:label="@string/documents_link_edit_activity_title" android:theme="@android:style/theme.black" > <intent-filter> <action android:name="de.hsaugsburg.hsapp.documents.intent.action.view" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity>
documentactivity.java:
public class documentactivity extends tabactivity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); refreshlist(); } @override public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); if (data != null && data.getaction().equals("action_refresh")) { refreshlist(); } } private void initlinkoptionmenu(final link selected) { final dialog dialog = new dialog(documentactivity.this); dialog.setcontentview(r.layout.documents_link_onclick_dialog); dialog.settitle("choose action..."); final button buttonopen = (button) dialog.findviewbyid(r.id.dlol_buttonopen); buttonopen.settext("open link!"); final imageview imageopen = (imageview) dialog.findviewbyid(r.id.dlol_imageopen); imageopen.setimageresource(r.drawable.ic_save); buttonopen.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { closedialog(dialog); openlink(selected); } }); final button buttonedit = (button) dialog.findviewbyid(r.id.dlol_buttonedit); buttonedit.settext("edit link!"); final imageview imageedit = (imageview) dialog.findviewbyid(r.id.dlol_imageedit); imageedit.setimageresource(r.drawable.ic_edit); buttonedit.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { closedialog(dialog); initeditdialog(dialog); } }); final button buttonshare = (button) dialog.findviewbyid(r.id.dlol_buttonshare); buttonshare.settext("share link!"); final imageview imageshare = (imageview) dialog.findviewbyid(r.id.dlol_imageshare); imageshare.setimageresource(r.drawable.ic_share2); final button dialogbutton = (button) dialog.findviewbyid(r.id.dlol_dialogbuttonok); dialogbutton.settext("close"); dialogbutton.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { closedialog(dialog); } }); dialog.show(); } private void initeditdialog(final dialog dialog) { new urlactivity().showdialog(r.layout.documents_link_editlink); log.info("urlactivity started: "); startactivity(new intent(this, urlactivity.class)); dialog.setcontentview(r.layout.documents_link_editlink); dialog.show(); final dialog dialog2 = new dilog(urlacitivty.this); dialog2.show() } private void refreshlist() { try { final asynctask<string, void, string> result = requester .requestcategory(getbasecontext()); final string res = result.get(); if (res != null) { categories = inputmanager.parsecategories(res); setcontentview(r.layout.documents_main); tabs = (tabhost) findviewbyid(android.r.id.tabhost); tabs.clearalltabs(); (final category category : categories) { final tabhost.tabspec spec = tabs.newtabspec(category .getname()); spec.setindicator(category.getname()); spec.setcontent(new tabhost.tabcontentfactory() { public view createtabcontent(string tag) { final listview list = new listview( documentactivity.this); final string[] links = new string[category .getlinks().size()]; int = 0; (link link : category.getlinks()) { links[i++] = link.getname(); } final arrayadapter<string> adapter = new arrayadapter<string>( documentactivity.this, r.layout.documents_listitem, links); list.setadapter(adapter); list.setoncreatecontextmenulistener(documentactivity.this); list.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> adapterview, view view, int i, long l) { final link selected = category.getlinks() .get(i); /* * defines several behaviours each link. */ initlinkoptionmenu(selected); } }); return list; } }); tabs.addtab(spec); } } else { toast.maketext(getapplicationcontext(), r.string.cannot_receive_from_server, toast.length_long) .show(); } } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); toast.maketext(getapplicationcontext(), e.getmessage(), toast.length_long).show(); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); toast.maketext(getapplicationcontext(), e.getmessage(), toast.length_long).show(); } catch (executionexception e) { // todo auto-generated catch block e.printstacktrace(); toast.maketext(getapplicationcontext(), e.getmessage(), toast.length_long).show(); } } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.layout.documents_menu, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { final intent intent = new intent(); switch (item.getitemid()) { case (r.id.menu_home): intent.setclass(documentactivity.this, de.hsaugsburg.hsapp.hsappactivity.class); break; case (r.id.menu_addurl): // this.addurl(); intent.setclass(documentactivity.this, de.hsaugsburg.hsapp.documents.addurlactivity.class); final int tabid = tabs.getcurrenttab(); final category selected = categories.get(tabid); intent.setdata(uri.parse("content://category/" + selected.getid())); break; case (r.id.menu_options): intent.setclass(documentactivity.this, de.hsaugsburg.hsapp.documents.optionsactivity.class); break; } startactivityforresult(intent, 0); return true; } private void closedialog(dialog dialog) { dialog.dismiss(); } }
urlactivity.java
public class urlactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); log.info("urlactivity oncreate created!"); this.dialogcontext = urlactivity.this; final dialog dialog = new dialog(this.dialogcontext); final button buttoncancel = (button) dialog.findviewbyid(r.id.documents_link_edit_cancel); buttoncancel.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { closedialog(dialog); } }); dialog.show(); } }
documents_link_onclick_dialog.xml
<?xml version="1.0" encoding="utf-8"?> <!-- custom dialog custom link options --> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <imageview android:id="@+id/dlol_imageopen" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="2dp" /> <button android:id="@+id/dlol_buttonopen" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_torightof="@+id/dlol_imageopen" android:text=" open " android:textcolor="#fff" /> <imageview android:id="@+id/dlol_imageshare" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="2dp" android:layout_margintop="6dp" android:layout_below="@+id/dlol_imageopen" /> <button android:id="@+id/dlol_buttonshare" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_torightof="@+id/dlol_imageshare" android:layout_below="@+id/dlol_buttonopen" android:text=" edit " android:textcolor="#fff" /> <imageview android:id="@+id/dlol_imageedit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="2dp" android:layout_margintop="6dp" android:layout_below="@+id/dlol_imageshare" /> <button android:id="@+id/dlol_buttonedit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_torightof="@+id/dlol_imageedit" android:layout_below="@+id/dlol_buttonshare" android:text=" edit " android:textcolor="#fff" /> <button android:id="@+id/dlol_dialogbuttonok" android:layout_width="100px" android:layout_height="wrap_content" android:layout_below="@+id/dlol_buttonedit" android:layout_marginright="2dp" android:layout_margintop="6dp" android:layout_centerhorizontal="true" android:text=" ok " /> </relativelayout>
documents_link_editlink.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".documents.urlactivity" > <edittext android:id="@+id/documentslinkedittitleinput" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparentright="true" android:layout_below="@+id/documentslinkedittitlelabel" android:ems="10" android:inputtype="text" > <requestfocus /> </edittext> <textview android:id="@+id/documentslinkedittitlelabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_marginleft="5dp" android:layout_margintop="10dp" android:text="@string/documents_link_edit_title" /> <edittext android:id="@+id/documentslinkediturlinput" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparentright="true" android:layout_below="@+id/documentslinkediturllabel" android:ems="10" android:inputtype="texturi" /> <spinner android:id="@+id/documentslinkedittypespinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/documentslinkedittypelabel" /> <spinner android:id="@+id/documentslinkeditcategoryspinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/documentslinkeditcategorylabel" /> <spinner android:id="@+id/documentslinkeditsortafterspinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/documentslinkeditsortafterlabel" /> <textview android:id="@+id/documentslinkeditcategorylabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/documentslinkedittypelabel" android:layout_below="@+id/documentslinkedittypespinner" android:text="@string/documents_link_edit_category" /> <textview android:id="@+id/documentslinkeditsortafterlabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/documentslinkeditcategorylabel" android:layout_below="@+id/documentslinkeditcategoryspinner" android:text="@string/documents_link_edit_sortafter" /> <textview android:id="@+id/documentslinkedittypelabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/documentslinkediturllabel" android:layout_below="@+id/documentslinkediturlinput" android:text="@string/documents_link_edit_type" /> <textview android:id="@+id/documentslinkediturllabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/documentslinkedittitlelabel" android:layout_below="@+id/documentslinkedittitleinput" android:text="@string/documents_link_edit_url" /> <tablerow android:id="@+id/tablerow1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/documentslinkeditsortafterspinner" > <button android:id="@+id/documents_link_edit_save" android:layout_width="0dp" android:layout_height="35dp" android:layout_weight="0.5" android:scaletype="fitxy" android:background="@drawable/button_save" /> <button android:id="@+id/documents_link_edit_cancel" android:layout_width="0dp" android:layout_height="35dp" android:layout_weight="0.5" android:scaletype="fitxy" android:background="@drawable/button_cancel" /> </tablerow> </relativelayout>
just start new activity within dialog's onclick()
, have new activity display new dialog (either implicitly, or passing in intent knows dialog show.
Comments
Post a Comment