2011-09-22 128 views
0
private void newGame() { 


     LayoutInflater inflater = (LayoutInflater) this 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     final PopupWindow pw = new PopupWindow(inflater.inflate(
       R.layout.settings, null, true), 300, 600, true); 

     pw.showAtLocation(this.findViewById(R.id.settings), Gravity.RIGHT, 0, 0); 

     pw.setTouchInterceptor(new OnTouchListener() { 

      public boolean onTouch(View v, MotionEvent event) { 
       // your code when touched on the event 


       return false; 
      } 

     }); 
    } 

我在这里发布了我的代码。我得到了弹出窗口。但我不知道如何添加事件到弹出窗口,并使其在点击后不可见。如何解开一个弹出窗口?

回答

0

呼叫的方法,该方法dismissonTouch

public boolean onTouch(View v, MotionEvent event) { 
     // your code when touched on the event 
     // you can add events here when the pop up window is touched 
     pw.dismiss(); 
     return true; 
    } 
+0

thanks..I使用的,但其不工作。 – preeti

+0

您是否收到错误?你检查日志吗? – bluefalcon

+0

我没有收到error.Its运行,但弹出式窗口不会被解雇。 – preeti

0

它是某种自定义的警报视图,这意味着某种文字的TextInput的,......以及一个或多个按钮(“OK”,“取消”)?

然后,你可以使用下面的代码:

protected Dialog onCreateDialog(int id) { 
    Dialog dialog = new Dialog(this); 
    switch (id) { 
    case DIALOG_HELP_ID: 
     // This example shows how to add a custom layout to an AlertDialog 
     LayoutInflater factory = LayoutInflater.from(this); 
     final View textEntryView = factory.inflate(
       R.layout.helpdialog_main, null); 
     return new AlertDialog.Builder(Main.this) 
       .setView(textEntryView) 
       .setPositiveButton(R.string.stringHelptextButtonOK, 
         new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, 
            int whichButton) { 

           // Popup is closed automatically, nothing 
           // needs to be done here 
          } 
         }).create(); 

    default: 
      dialog = null; 
     } 
     return dialog; 
    } 
0
public class Pop extends Activity { 
    PopupWindow pw; 

    /** Called when the activity is first created. */ 
    Button ok; 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     ok = (Button) findViewById(R.id.but); 
     ok.setOnClickListener(new View.OnClickListener() 
     { 
      @Override 
      public void onClick(View v) { 

       LayoutInflater inflater = (LayoutInflater)Pop.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

       pw = new PopupWindow(inflater.inflate(R.layout.popup,null, false),400,400,true); 

       pw.showAtLocation(findViewById(R.id.mainn), Gravity.BOTTOM, 0,0); 
      } 
     }); 
    } 

    public void onbuttonClick(View v) { 

     Intent openstartingpoint2=new Intent("com.lee.pop.CLA"); 
     startActivity(openstartingpoint2); 

     pw.dismiss(); 
     return ; 
    } 
} 
0

如何处理弹出窗口和警报 - 只要按照此代码 -

import java.util.Iterator; 
import java.util.Set; 

import org.openqa.selenium.Alert; 
import org.openqa.selenium.By;`enter code here` 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 


public class Alart_Pop_Handel { 

    public static void main(String[] args) { 

     WebDriver driver = new FirefoxDriver(); 
     Set<String> wind = driver.getWindowHandles(); 
     System.out.println("total window size -> " +wind.size()); 
     // blank fire fox will open 

     Iterator<String> it = wind.iterator(); 
     System.out.println(it.next()); // show the window id 
     driver.get("http://in.rediff.com/"); 

     wind = driver.getWindowHandles(); // call one more time to get window 
     it = wind.iterator(); 
     System.out.println(" total window size -> " +wind.size()); 
     // show 2 window and id 

     // handel pop up 
     // create string 

     String main= it.next(); 
     String pop= it.next(); 

     System.out.println(main); // take a print for both window id 
     System.out.println(pop); 

     driver.switchTo().window(pop); // control change to pop up 
     driver.close();     // close pop up 
     driver.switchTo().window(main); // get back to main window 

     System.out.println("************ main window id*****************"); 
     System.out.println(main); // make sure the main window id will see 

     //click signin 

     driver.findElement(By.xpath(".//*[@id='signin_info']/a[1]")).click(); 
     driver.findElement(By.xpath("//input[@type='submit']")).click(); 

     // handel alert 
     Alert al=driver.switchTo().alert(); 
     System.out.println(al.getText()); 
     al.accept(); 
     driver.switchTo().defaultContent(); 
相关问题