2013-08-21 60 views
0

感謝您的閱讀並對我的英語感到抱歉。 我的問題是,我的Android應用程序應該顯示一個帶有imageview和textview的佈局。 Intead認爲它不顯示圖像和文本,它開始運行該活動的代碼並啓動下一個活動而不顯示它。佈局顯示爲空

¿在執行其餘代碼之前,我該如何強制它顯示?

感謝您的回覆。

我的代碼:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.lay_inicio);   

    //Inicio de la actividad: 
    //1-Obtiene la IP del PC 
    Intent i; 
    String IP = getIP(); 
    if(IP == null){//Si no se ha obtenido la IP se pregunta si se desea salir o reintentarlo 
     i = new Intent(this,ReintentarSalir.class); 
     startActivity(i); 
    } 
    else{ 
     //2-Envia su IP al PC 
     sendIP(IP); 

     //3-Se pasa a la actividad en la que se pregunta si se desea enviar o recibir datos 
     i = new Intent(this,EnviarRecibir.class); 
     i.putExtra("IP", IP); 
     startActivity(i); 
     finish(); 
    } 
    finish(); 
} 

我希望「lay_inicio」佈局,調用函數getIP()

+10

添加代碼... –

+0

+1,我們需要你的代碼,以幫助您 –

+0

@維克多出示你的代碼什麼ü試圖.. – FarhaSameer786

回答

0

如果你想要的東西一樣閃屏,然後有一個閃屏活動之前顯示。使用線程顯示一段時間,然後啓動另一個活動。事情是這樣的:

public class SplashScreen extends Activity { 

    /** 
    * The thread to process splash screen events 
    */ 
    private Thread mSplashThread; 
    private final static int SPLASH_SCREEN_TIME = 1500; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     // Splash screen view 
     setContentView(R.layout.splash); 

     final SplashScreen sPlashScreen = this; 

     // The thread to wait for splash screen events 
     mSplashThread = new Thread(){ 
      @Override 
      public void run(){ 
       try { 
        synchronized(this){ 
         // Wait given period of time or exit on touch 
         wait(SPLASH_SCREEN_TIME); 
        } 
       } 
       catch(InterruptedException ex){      
       } 

       // Run next activity 
       Intent intent = new Intent(); 
       intent.setClass(sPlashScreen, HomeScreenActivity.class); 
       intent.putExtra("showTheme", true); 
       intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
       startActivity(intent); 
       finish(); 
      } 
     }; 

     mSplashThread.start();   
    } 

    /** 
    * Processes splash screen touch events 
    */ 
    @Override 
    public boolean onTouchEvent(MotionEvent evt) 
    { 
     if(evt.getAction() == MotionEvent.ACTION_DOWN) 
     { 
      synchronized(mSplashThread){ 
       mSplashThread.notifyAll(); 
      } 
     } 
     return true; 
    }  
} 
+0

蘇希爾謝謝!這工作得很好!非常感謝。 – Victor

+0

高興地幫助,很高興知道它爲你工作:) – Sushil