开发者

Android Dialog alert

I want to create custom dialog for entering text and date. For that i have created a layout xml file which is

<?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" android:orientation="vertical">
    <EditText android:id="@+id/dialogEditText" android:text="Enter Your Text Here" android:layout_height="wrap_content" android:layout_width="match_parent"></EditText>
    <DatePicker android:id="@+id/datPicker" android:layout_height="wrap_content" android:layout_width="match_parent" ></DatePicker>
    <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">
     <Button android:text="Add" android:id="@+id/dialogAddBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true"></Button>
     <Button android:text="Cancel" android:id="@+id/dialogCancelBtn" android:layout_width="200px" android:layout_height="wrap_content" android:layout_centerHorizontal="true"></Button>
    </LinearLayout>
</LinearLayout>

and my class code is :

  final Dialog d= new Dialog(obj);
                 Window window= d.getWindow();
                 window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
                 window.setTitle("Add Item");
                 window.setContentView(R.layout.dialog_view);

                 final EditText input= (EditText) obj.findViewById(R.id.dialogEditText);
                 Button okBtn= (Button) obj.findViewById(R.id.dialogAddBtn);
                 okBtn.setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            toDoItems.add(0,input.getText().toString());
                              aa.notifyDataSetChanged();
                              //d.dismiss();
                        }
                    });
                    d.show();

This is showing dialog perfectly but when i click on ok than it is generating exception which is :

04-06 14:01:24.415: ERROR/AndroidRuntime(1189): FATAL EXCEPTION: main
04-06 14:01:24.415: ERROR/AndroidRuntime(1189): java.lang.NullPointerException
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at 开发者_如何学Pythoncom.example.wrox.MyDialog.showInputDialog(MyDialog.java:66)
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at com.example.wrox.ToDoItems$1.onClick(ToDoItems.java:69)
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at android.view.View.performClick(View.java:2485)
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at android.view.View$PerformClick.run(View.java:9080)
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at android.os.Handler.handleCallback(Handler.java:587)
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at android.os.Looper.loop(Looper.java:123)
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at java.lang.reflect.Method.invokeNative(Native Method)
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at java.lang.reflect.Method.invoke(Method.java:507)
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-06 14:01:24.415: ERROR/AndroidRuntime(1189):     at dalvik.system.NativeStart.main(Native Method)

Please suggest me some solutions.......


See my answer on following link. Android: Dialog dismisses without calling dismiss

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜