2017-03-07 1 views
0

J'essaie de montrer popup sur activity on create() méthode mais rien ne semble se produire .. Non exception no popup.Montrer pop up sur l'activité de création échoue

code suivant est

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_login); 
    btnClear = (Button)findViewById(R.id.btnClear); 
    txtPassword = (TextView) findViewById(R.id.txtPassword); 
    txtPassword.setOnTouchListener(otl); 
    btnClear.setVisibility(View.GONE); 
    objDBHelper = DBHelper.getInstance(getApplicationContext()); 
    SQLiteDatabase db = objDBHelper.getWritableDatabase(); 
    long driverProfileCount = objDBHelper.getProfilesCount(db); 

     initiatePasswordPopupWindow(); // show pop up when no data is in table 

} 

private void initiatePasswordPopupWindow() { 
    try { 
     //We need to get the instance of the LayoutInflater, use the context of this activity 
     LayoutInflater inflater = (LayoutInflater) Login.this 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     //Inflate the view from a predefined XML layout 
     final View layout = inflater.inflate(R.layout.setting_password_popup, 
       (ViewGroup) findViewById(R.id.setting_password_popup_element)); 
     // create a 300px width and 470px height PopupWindow 
     pw = new PopupWindow(layout, 600, 720, true); 
     // display the popup in the center 
     layout.post(new Runnable() { 
      public void run() { 
       pw.showAtLocation(layout, Gravity.CENTER, 0, 0); 
       Button cancelButton = (Button) layout.findViewById(R.id.end_data_send_button); 
       cancelButton.setOnClickListener(cancel_button_click_listener); 
      } 
     }); 

     /* TextView mResultText = (TextView) layout.findViewById(R.id.server_status_text);*/ 


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

Qu'est-ce que je suis absent?

+0

Etes-vous sûr driverProfileCount est en fait Equalt à 0? – StarterPack

+0

Êtes-vous sûr 'driverProfileCount == 0'? –

+0

afficher le code complet, car nous ne pouvons pas dire si 'driverProfileCount' est zéro –

Répondre

1

Vous essayez d'utiliser post avec la vue (disposition PopupWindow) qui ne démarre pas la file d'attente des messages. Essayez d'utiliser la vue qui est déjà en activité, par exemple vue racine - changement layout.post(new Runnable() {-findViewById(android.R.id.content):

findViewById(android.R.id.content).post(new Runnable() { 
    public void run() { 
     pw.showAtLocation(layout, Gravity.CENTER, 0, 0); 

     Button cancelButton = (Button) layout.findViewById(R.id.end_data_send_button); 
     cancelButton.setOnClickListener(cancel_button_click_listener); 
    } 
}); 
+0

Cette solution fonctionne ... Merci !!! –