2013-03-05 86 views
0

我想在我的应用程序来创建输入文本字段,并确定和取消按钮的弹出窗口:Android的弹出窗口

这是我在MainActivity代码:

forgotPassword.setOnClickListener(new View.OnClickListener() { 

       public void onClick(View v) { 
        View pview = inflater.inflate(R.layout.forgot_password_popup,(ViewGroup)findViewById(R.layout.login)); 

        final PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.forgot_password_popup,(ViewGroup)findViewById(R.layout.login))); 
        pw.showAtLocation(v, Gravity.LEFT,0,0); 
        pw.update(8,-70,150,270); 

        //if onclick written here, it gives null pointer exception. 
        Button okbtn=(Button)pview.findViewById(R.id.okbtn); 
        Button cancelbtn = (Button)pview.findViewById(R.id.cancelbtn); 
        final EditText emailText = (EditText) pview.findViewById(R.id.EmailText); 
        okbtn.setOnClickListener(new OnClickListener() 
        { 
         public void onClick(View v) 
         { 
          try { 
           ParseUser.requestPasswordReset(emailText.getText().toString()); 
          } catch (ParseException e) { 
           // TODO Auto-generated catch block 
           e.printStackTrace(); 
          } 
         } 
        }); 

        cancelbtn.setOnClickListener(new OnClickListener() 
        { 
         public void onClick(View v) 
         { 
          pw.dismiss(); 

         } 
       }); 

       } 
      }); 

这里是我忘了password_popup .XML:

<?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="wrap_content" 
     android:orientation="vertical" > 

    <EditText 
     android:id="@+id/EmailText" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dip" 
     android:hint="Enter Email Address" 
     android:inputType="textEmailAddress" 
     android:password="true" 
     android:singleLine="true" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/okbtn" 
      android:layout_width="80dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="50dp" 
      android:text="OK" /> 

     <Button 
      android:id="@+id/cancelbtn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="50dp" 
      android:text="Cancel" /> 
    </LinearLayout> 

    </LinearLayout> 

但它切断(我看不到文本字段或取消按钮,也没有任何背景的弹出窗口(我希望有一个透明背景)

而且,我不能点击确定按钮,这样有毛病我的代码

我会很高兴的帮助

这是它的样子:

http://img827.imageshack.us/img827/9545/capturehdv.png

非常感谢

+0

http://developer.android.com/guide/topics/ui/dialogs.html – 2013-03-05 16:18:38

+0

谢谢,我会看它,也,你知道如何创建它trasperanct?谢谢 – 2013-03-05 16:22:08

+0

@AdirRahamim你尝试我发布的内容..? – Pragnani 2013-03-05 16:24:23

回答

0

简单的解决方案是采取一个tranparent图像,并将其设置为您的弹出式布局的背景。

而且还尝试

android:[email protected] 
+0

它说这是不被接受的价值,没有为我工作 – 2013-03-05 16:27:24

+0

@null应该在引号中。最佳解决方案是在photoshop或任何照片编辑器中创建透明图像,并将其设置为弹出式父级布局的背景 – Pragnani 2013-03-05 16:28:54