为什么我的自定义警告对话框code崩溃? [英] Why is my custom alert dialog code crashing?

查看:186
本文介绍了为什么我的自定义警告对话框code崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想申请定制视图提醒对话框。我在做这个样子,但空指针异常,当我尝试显示警告框。

I'm trying to apply custom view to alert dialog. I'm doing like this, but there is nullpointer exception when I try to show the alert box.

我创建了一个layout.xml像这样:

I create a layout.xml like so:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"  
  android:id="@+id/themescreen"
  android:gravity="center"
  android:orientation="horizontal"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
 >
<TableLayout
android:padding="45dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioGroup
android:gravity="center">
<TableRow>
<RadioButton
android:id="@+id/rdthemeBlue"
android:button="@drawable/radio_custom">
</RadioButton>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/bluebackgroundicon"
android:paddingLeft="10dip"
android:paddingBottom="10dip"
></ImageView>
</TableRow>
<TableRow>
<RadioButton
android:id="@+id/rdthemeGolden"
android:button="@drawable/radio_custom"></RadioButton>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/goldenredbackgroundicon"
android:paddingLeft="10dip"
android:paddingBottom="10dip"
></ImageView>
</TableRow>

<TableRow>
<RadioButton
android:id="@+id/rdthemeBlack"
android:button="@drawable/radio_custom">
</RadioButton>
<TextView
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:text="None"
>
</TextView>
</TableRow>
</RadioGroup>
<TableRow
android:paddingTop="25dip"
android:paddingLeft="10dip"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
>
<Button
android:id="@+id/btnthemesave"
android:background="@drawable/btn_custom"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:text="Save"
android:textSize="15sp"
 ></Button>
<Button
android:id="@+id/btnthemecancel"
android:background="@drawable/btn_custom"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:text="Cancel"
android:textSize="15sp"
></Button>
</LinearLayout>
</TableRow>
</TableLayout>
</LinearLayout>

和通过这个code申请alertbox。

and applying to alertbox through this code.

 LayoutInflater factory = LayoutInflater.from(BackupRestoreActivityContext);  
  final View textEntryView = factory.inflate(R.layout.layout,null); 
    AlertDialog.Builder alert = new AlertDialog.Builder(BackupRestoreActivityContext);          
           alert.setTitle("Configuration Setting"); 
          alert.setView(textEntryView);   
      alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() 
          {     
              public void onClick(DialogInterface dialog, int whichButton) {  

                    return;          
                  }      
              });      
          alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() 
          {     
              public void onClick(DialogInterface dialog, int which) {   
                  // TODO Auto-generated method stub       
                  return;      
                  }  
              });     
          alert.show();     

这可能是导致空指针异常?

What could be causing the null pointer exception?

推荐答案

尝试与这些code的警告对话框的工作对我来说

Try with these code for Alert Dialog its working for me

AlertDialog.Builder alert;
alert = new AlertDialog.Builder(Deal_Purchase_Checkout.this);
alert.setTitle("Enter Your Title");
alert.setView(input);
alert.setPositiveButton("Ok",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int whichButton){
    //Some Code
 }
});
alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int whichButton) {
        dialog.cancel();
    }
});
alert.show();

这篇关于为什么我的自定义警告对话框code崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆