2016-08-02 43 views
0

我想在彈出窗口中設置活動的內容.. 就像我想在活動中提到設置按鈕文本一樣。 這裏是我的代碼和他們各自的文件。如何在android中的彈出窗口中設置活動?

popupscreen.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/popup_element" 
    android:background="#7000"> 


<Button 
    android:id="@+id/btn_close_popup" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    /> 

</LinearLayout> 

PopupScreen.java

public class PopupScreen extends AppCompatActivity { 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.screen_popup); 
    Button bt=(Button)findViewById(R.id.btn_close_popup); 
    bt.setText("close this"); 
    } 

    // And this is Popup window code in MainActivity 

    private PopupWindow pwindo; 
    private void opPopupWindow(){ 
    try { 

     LayoutInflater inflater = (LayoutInflater)MainActivity.this 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View layout = inflater.inflate(R.layout.screen_popup, 
       (ViewGroup) findViewById(R.id.popupscreen)); 

     pwindo = new PopupWindow(layout, 400, 470, true); 
     pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0); 

     btnClosePopup = (Button) layout.findViewById(R.id.btn_close_popup); 
     btnClosePopup.setOnClickListener(cancel_button_click_listener); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

現在我想設置按鈕文本提到在PopupScreen.Java

+0

請參閱DialogFragment – CSmith

+0

什麼?我不明白你想達到什麼目的,我懷疑有沒有人會這樣做。 –

+0

@AmitKumawat進行自定義對話框 –

回答

0

創建PopupScreen.java一個DialogFragment作爲

public class PopupScreen extends DialogFragment { 
    public static String TAG = PopupScreen.class.getSimpleName(); 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup 
      container, Bundle savedInstanceState) { 
     return inflater.inflate(R.layout.screen_popup, container, false); 
    } 
} 

然後從您想要彈出屏幕的活動中調用它。

PopupScreen popupScreen = new PopupScreen(); 
popupScreen.show(getFragmentManager(), PopupScreen.TAG); 
相關問題