2011-10-29 5 views
1

これはおそらく私がやろうとしている簡単なことですが、私はデフォルトのアンドロイドの読み込み画面を表示し、テキストを代わりに "消費しています..." 「Android Cookbookのチュートリアルに基づいてこれをやっています。ここに私のコードとXMLファイルがあります。他のコードが必要な場合は、私に知らせてください。私は正直なところ、おそらく何か愚かなことをしていますが、私は知る必要があります。私は問題が何であるか確信しているので、logcatで何も起こっていません。しかし、本は時代遅れかもしれません。また、私はAndroid 2.2を実行しており、Samsung Galaxy 4Gでテストしていることにも注意してください。Android "Loading .."のテキストを変更

もう少し情報が必要だと思います。私はAndroidデベロッパーのクックブックで時間消費の初期化レシピを処理しようとしています。http://bit.ly/sFoBn6 単純なテキストスプラッシュ画面が必要です。プログレスバーでもありません。私たちは今、単純なばかげた話をしています。私はまだAndroidを学んでいます。私はちょうど "..読み込んでいます" それは通常のをやりたいではなく、それは

HandleMessage.java

package com.cookbook.handle_message; 

import android.app.Activity; 
import android.os.Bundle; 
import android.os.Handler; 
import android.os.Message; 
import android.widget.TextView; 

public class HandleMessage extends Activity implements Runnable { 
    /** Called when the activity is first created. */ 
    TextView mTestLabel; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     mTestLabel = (TextView) findViewById(R.id.test); 

     Thread thread = new Thread(this); 
     thread.start(); 
    } 

    private Handler mHandler = new Handler() { 
     public void handleMessage(Message msg) { 
      setContentView(R.layout.main); 
     } 
    }; 

    public void run() { 
     initializeArrays(); 
     mHandler.sendEmptyMessage(0); 
    } 

    final static int NUM_SAMPS = 1000; 
    static double[][] correlation; 

    void initializeArrays() { 
     if(correlation!=null) return; 

     correlation = new double[NUM_SAMPS][NUM_SAMPS]; 
     for(int k=0; k<NUM_SAMPS; k++){ 
      for(int m=0; m<NUM_SAMPS; m++){ 
       correlation[k][m] = Math.cos(2*Math.PI*(k+m)/1000); 
      } 
     } 
    } 
} 

のres /レイアウト/ main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 


    <TextView 
     android:id="@+id/test" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

</LinearLayout> 
"...消費を" と言ってい

RES /レイアウト/ loading.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <TextView android:id="@+id/loading" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Consuming..."/> 
</LinearLayout> 

のAndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.cookbook.handle_message" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="8" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:label="@string/app_name" 
      android:name=".HandleMessage" > 
      <intent-filter > 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

答えて

0

多分あなたは進捗インジケータか何かをしたいですか?進行中の進行状況バーを更新する長い実行スレッドでアクティビティを開始する方法を示すthis page for an exampleを参照してください。

また、LogCatには何も表示されませんでした。あなたのコードにいくつかのLog.iステートメントを入れて、何が起こっているのかを見てください。

EDIT:上記のコードでは、2つのレイアウトを使用しないでください。ちょうど1を使用してください。あなたのハンドラで、テキストビューのテキストを変更してください。

public void handleMessage(Message msg) { 
     TextView tv=(TextView)findViewById(R.id.loading); 
     tv.setText("All Done"); 
    } 

はそれを得る:あなたはloading.xmlを使用する場合

だから、単にような何かを行うのonCreateにして、あなたのハンドラでその設定されていますか?間違いなく、この種のものに対してsetContentViewを2回も呼び出さないでください。それを行う方法があるかもしれないので、おそらくそれはその用途を持っていますが、私はそれをやったことはありません。また、私はいくつかのもののためにスレッドとハンドラの代わりにAsyncTaskを使用し始めました。

また、何か問題が発生していない場合は、何が起きているのかを知るためにLogステートメントを追加してください。

+0

バックグラウンドタスクが実行されている間、単純なテキストスプラッシュ画面を表示したいだけです。 – bagelbits

+0

これらのどちらも私のために働くでしょう。ありがとうございました! – bagelbits

関連する問題