android - Custom Dialog, setContentView throws ResourceNotFoundException -



android - Custom Dialog, setContentView throws ResourceNotFoundException -

i'm using this tutorial create custom dialog should shown when click on "create new folder" spinner. within onitemsselected method, check "create new folder" alternative clicked, , want show dialog introduce name of new folder. i'm doing this:

res/layout/dialog.html

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialog" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="visible" > <edittext android:id="@+id/edittext_dialog" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:hint="@string/edittext_dialog" android:layout_alignparenttop="true" android:layout_margintop="15dip" android:layout_marginbottom="15dip"/> <button android:id="@+id/button_create_dialog" android:text="@string/button_create_dialog" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/edittext_dialog" android:layout_alignparentleft="true" android:layout_marginleft="50dip" android:background="#176cec" android:textcolor="#fff" android:textstyle="bold" android:textappearance="?android:attr/textappearancelarge"/> <button android:id="@+id/button_cancel_dialog" android:text="@string/button_cancel_dialog" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/edittext_dialog" android:layout_alignparentright="true" android:layout_marginright="50dip" android:background="#176cec" android:textcolor="#fff" android:textstyle="bold" android:textappearance="?android:attr/textappearancelarge"/> </relativelayout>

java file

public void onitemselected(adapterview<?> parent, view view, int position,long id){ if (parent.getitematposition(position).tostring().matches("create new folder")){ final dialog dialog = new dialog(this); seek { dialog.setcontentview(r.id.dialog); dialog.settitle("create new folder"); } grab (exception e){ stringwriter errors = new stringwriter(); e.printstacktrace(new printwriter(errors)); log.i("exception", errors.tostring()); } button createbutton = (button) findviewbyid(r.id.button_create_dialog); button cancelbutton = (button) findviewbyid(r.id.button_cancel_dialog); createbutton.setonclicklistener(new button.onclicklistener(){ public void onclick(view v){ edittext newfoldername = (edittext) findviewbyid(r.id.edittext_dialog); string foldername = newfoldername.gettext().tostring().trim(); if (foldername.length() > 0) { // stuff dialog.dismiss(); } } }); cancelbutton.setonclicklistener(new button.onclicklistener(){ public void onclick(view v){ dialog.dismiss(); } }); dialog.show(); } }

i'm getting resourcenotfoundexception. stacktrace:

11-07 17:11:49.075: i/exception(8315): android.content.res.resources$notfoundexception: resource id #0x7f05000e 11-07 17:11:49.075: i/exception(8315): @ android.content.res.resources.getvalue(resources.java:1118) 11-07 17:11:49.075: i/exception(8315): @ android.content.res.resources.loadxmlresourceparser(resources.java:2304) 11-07 17:11:49.075: i/exception(8315): @ android.content.res.resources.getlayout(resources.java:934) 11-07 17:11:49.075: i/exception(8315): @ android.view.layoutinflater.inflate(layoutinflater.java:395) 11-07 17:11:49.075: i/exception(8315): @ android.view.layoutinflater.inflate(layoutinflater.java:353) 11-07 17:11:49.075: i/exception(8315): @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:267) 11-07 17:11:49.075: i/exception(8315): @ android.app.dialog.setcontentview(dialog.java:471) 11-07 17:11:49.075: i/exception(8315): @ com.example.example.mainactivity.onitemselected(mainactivity.java:94) 11-07 17:11:49.075: i/exception(8315): @ android.widget.adapterview.fireonselected(adapterview.java:892) 11-07 17:11:49.075: i/exception(8315): @ android.widget.adapterview.access$200(adapterview.java:49) 11-07 17:11:49.075: i/exception(8315): @ android.widget.adapterview$selectionnotifier.run(adapterview.java:860) 11-07 17:11:49.075: i/exception(8315): @ android.os.handler.handlecallback(handler.java:730) 11-07 17:11:49.075: i/exception(8315): @ android.os.handler.dispatchmessage(handler.java:92) 11-07 17:11:49.075: i/exception(8315): @ android.os.looper.loop(looper.java:137) 11-07 17:11:49.075: i/exception(8315): @ android.app.activitythread.main(activitythread.java:5103) 11-07 17:11:49.075: i/exception(8315): @ java.lang.reflect.method.invokenative(native method) 11-07 17:11:49.075: i/exception(8315): @ java.lang.reflect.method.invoke(method.java:525) 11-07 17:11:49.075: i/exception(8315): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:737) 11-07 17:11:49.075: i/exception(8315): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 11-07 17:11:49.075: i/exception(8315): @ dalvik.system.nativestart.main(native method)

as can imagine, resource id #0x7f05000e matches r.id.dialog, i've checked it:

inside r.java

public static final int dialog = 0x7f05000e;

any thought can problem?

update forgot exception thrown on line:

dialog.setcontentview(r.id.dialog);

this error occurred because seek findviewbyid on view(s) not exists in activity, exists in dialog.

change code :

button createbutton = (button) findviewbyid(r.id.button_create_dialog); button cancelbutton = (button) findviewbyid(r.id.button_cancel_dialog);

to :

button createbutton = (button) dialog.findviewbyid(r.id.button_create_dialog); button cancelbutton = (button) dialog.findviewbyid(r.id.button_cancel_dialog);

those buttons not in activity, cant phone call findviewbyid because seek find button's id in activity's xml. instead, phone call dialog.findviewbyid tell code find button in dialog.

update (sorry no code tag, update phone)

you should utilize r.layout.dialog instead of r.id.dialog in setcontentview method.

android dialog android-resources r.java-file

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -