android - Error when I add a view to a AlertDialog? -


i make new dialog allow users input name , password login. have added snippets here:

        layoutinflater flater = layoutinflater.from(context);         final view view = flater.inflate(r.layout.login, null);          spinner spinner=(spinner)view.findviewbyid(r.id.safequestion_spinner);         arrayadapter<string> adapter=new arrayadapter<string>(context,android.r.layout.simple_dropdown_item_1line,safequestion);         spinner.setadapter(adapter);          spinner.setonitemselectedlistener(new adapterview.onitemselectedlistener() {             @override             public void onitemselected(adapterview<?> adapterview, view view, int i, long l) {                 questionid=""+i;                 if(i!=0)                     ((edittext)view.findviewbyid(r.id.answear_edittext)).setvisibility(0);             }              @override             public void onnothingselected(adapterview<?> adapterview) {                 questionid=""+0;             }         });          new alertdialog.builder(context).seticon(r.drawable.hi).settitle(r.string.userlogin).setview(view)                 .setnegativebutton(r.string.cancel, new dialoginterface.onclicklistener() {                     @override                     public void onclick(dialoginterface dialoginterface, int i) {                         ((activity) context).finish();                     }                 }).setpositivebutton(r.string.login, new dialoginterface.onclicklistener() {             @override             public void onclick(dialoginterface dialoginterface, int i) {                 //进行登陆验证                 name = ((edittext) view.findviewbyid(r.id.username_edittext)).gettext().tostring();                 password = ((edittext) view.findviewbyid(r.id.password_edittext)).gettext().tostring();                 if (questionid == "0")                     answear = "";                 else {                     answear = ((edittext) view.findviewbyid(r.id.answear_edittext)).gettext().tostring();                 }                 user user = new user(name, password, questionid, answear);                 login(user);                 if (isuseravailable == false)                     tools.checkuser(context);                 else {                     loggedinuser = user;                     editor.putstring("name",name);                     editor.putstring("password",password);                     editor.putstring("questionid",questionid);                     editor.putstring("answear",answear);                     editor.commit();                     context.startactivity(new intent(context,mainactivity.class));                     ((activity)context).finish();                 }             }         }).create().show(); 

added xml code:

<?xml version="1.0" encoding="utf-8"?>  <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"           android:orientation="vertical"           android:layout_width="match_parent"           android:layout_height="match_parent"> <linearlayout      android:layout_width="fill_parent"     android:layout_height="wrap_content"         >     <textview android:layout_width="wrap_content" android:layout_height="wrap_content"             android:text="@string/username"            />     <edittext android:layout_width="fill_parent" android:layout_height="wrap_content"             android:id="@+id/username_edittext"             /> </linearlayout>  <linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content">     <textview android:layout_width="wrap_content" android:layout_height="wrap_content"               android:text="@string/password"              />     <edittext android:layout_width="fill_parent" android:layout_height="wrap_content"               android:id="@+id/password_edittext"               android:password="true"             /> </linearlayout>  <spinner android:layout_width="fill_parent" android:layout_height="wrap_content"         android:layout_marginright="100dp"         android:id="@+id/safequestion_spinner"         ></spinner>  <edittext android:layout_width="fill_parent" android:layout_height="wrap_content"           android:id="@+id/answear_edittext"           android:visibility="invisible"         />  <textview android:layout_width="wrap_content" android:layout_height="wrap_content"         android:id="@+id/textview"         android:visibility="invisible"/> 

the wrong information is:

06-10 21:47:41.963 6725-6725/com.example.hipda e/androidruntime﹕ fatal exception: main android.view.inflateexception: binary xml file line #123: error inflating class @ android.view.layoutinflater.createview(layoutinflater.java:613) @ com.android.internal.policy.impl.phonelayoutinflater.oncreateview(phonelayoutinflater.java:56) @ android.view.layoutinflater.oncreateview(layoutinflater.java:660) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:685) @ android.view.layoutinflater.rinflate(layoutinflater.java:746) @ android.view.layoutinflater.rinflate(layoutinflater.java:749) @ android.view.layoutinflater.rinflate(layoutinflater.java:749) @ android.view.layoutinflater.inflate(layoutinflater.java:489) @ android.view.layoutinflater.inflate(layoutinflater.java:396) @ android.view.layoutinflater.inflate(layoutinflater.java:352) @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:409) @ com.android.internal.app.alertcontroller.installcontent(alertcontroller.java:240)

i don't know what's going on?could me? thank you!

onitemclicklistener cannot used spinner widget use spinner.setonitemselectedlistener instead.

spinner.setonitemselectedlistener(new onitemselectedlistener() { @override public void onitemselected(adapterview<?> parentview, view selecteditemview, int position, long id) {     // code here }  @override public void onnothingselected(adapterview<?> parentview) {     // code here }  }); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -