2011-12-05 13 views
0

スプラッシュ画面でAsynctaskを使用して、データベース項目をデータベースに追加しています。 挿入プロセスはうまくいったが、スプラッシュビューは表示されません。レイアウトビューでAsyncTaskをデバッグする際に助けが必要

私のコードを以下に掲載していますが、アドバイスをいただければ幸いです。 THX

splash.xml

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/splash"> 


</RelativeLayout> 

Splash.java

public class Splash extends Activity { 

    private ChannelDB mDB; 
    private TextView loading; 
    private String channelS_TABLE; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 
     new SetDB().execute(); 

    } 

    private class SetDB extends AsyncTask<String, String, String> { 

     @Override 
     protected String doInBackground(String... arg0) { 
      // TODO Auto-generated method stub 
      try { 
       if (tabIsExist(channelS_TABLE) !=true){ 
        **some database insert** 
       }else{ 
        synchronized(this){ 
         Log.i("Splash", "the table is there"); 
         wait(3000);} 
        Intent i = new Intent(); 
        i.setClassName("com.appkon.hdtvs", 
            "com.appkon.hdtvs.HDtvs"); 
        finish(); 
        startActivity(i); 
       } 
       }catch (Exception e) { 

        Log.i("Splash", "setDB exception"); 
         Intent i = new Intent(); 
         i.setClassName("com.appkon.hdtvs", 
             "com.appkon.hdtvs.HDtvs"); 
         finish(); 
         startActivity(i); 
        } 
      return null; 
     } 


     protected void onPreExecute(String load) { 
      synchronized (this) { try { 
       wait(2000); 
      } catch (InterruptedException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } } 
     } 

     protected void onPostExecute(String finish) { 
      Intent i = new Intent(); 
      i.setClassName("com.appkon.hdtvs", 
          "com.appkon.hdtvs.HDtvs"); 
      finish(); 
      startActivity(i); 
     } 
    } 


     public boolean tabIsExist(String tableName){ 
      boolean result = false; 
      if(tableName == null){ 
        return false; 
      } 
      Cursor cursor= ChannelDB.check(); 
      startManagingCursor(cursor); 
      try { 
        if(cursor.moveToNext()){ 
          int count = cursor.getInt(0); 
          if(count>0){ 
            result = true; 
          } 
        } 

      } catch (Exception e) { 
       Log.e(this.toString(),"error:"+e.toString()); 
       Intent intent = new Intent(this,HDtvs.class); 
       startActivity(intent); 
       this.finish(); 
      }     
      return result; 
     } 


    } 

は私が

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/splash"> 

    <ImageView android:id="@+id/bg" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/splash"/> 

</LinearLayout> 

はまだ働いていないと、データベースの挿入があまりにもworkongされていないXMLを変更しました。

+0

なぜ、あなたは 'onPreExecute'で2秒待ってUIスレッドをストールしていますか? –

+0

あなたの意見はどこですか? RelativeLayoutの下にImageViewを定義する必要があります。それ以外の場合は、空白の画面が表示されます。 –

答えて

0

RelativeLayoutはコンテナです。その背景は、内部にいくつかの要素/ビューがある場合にのみ表示されます。私はそれについて確信していません。しかし、これを試すことができます - RelativeLayoutの背景からイメージを削除し、RelativeLayoutの中にImageViewを作成し、ImageView'sソースイメージを目的のイメージとして設定します。目的の結果が得られるはずです。

+0

RelativeLayoutの背景が機能しないことは確かですか? –

+0

@PareshMayaniいいえ、私はそうではありません。私はそれを示すために私の答えを編集しました。 –

+0

@アキよく、問題はまだそこにあり、私はsetDBの例外があることに気づいた – oratis

関連する問題