2011-09-22 168 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(); 
相關問題