0

2 つのクイック mp3 ファイルを数秒間隔で再生するシンプルなアプリを作成しています。タイミングのためにスレッドを使用しています

スレッド内で、myquick という xml ファイルに対して setText を実行すると、問題なく動作しますが、10 秒待機した後、次の mp3 ファイルが呼び出されると、次の setText が機能せず、強制的に閉じられます。問題のあるコードをコメントアウトすると...

// mytxt.setText("これで終わります");

スレッド全体がそのペースを通り抜けてから、喜んでリストビュー メニューに戻ります。

質問...どうすれば画面上のテキストを変更できますか? どうすればこれを機能させることができますか?

ここに私の2つの関連ファイルがあります

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

  >

<TextView
    android:id="@+id/ses1text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_gravity="center"
    android:gravity="center"
    android:textColor="@android:color/white"
    android:text=" "
    android:textSize="25dp" >
</TextView>

</RelativeLayout>

そして、これが問題のある私のJAVAコードです

public class MyQuick extends Activity {

MediaPlayer mp;
Thread threetimer;


@Override
public void onCreate(Bundle twothings) {
    // TODO Auto-generated method stub
    super.onCreate(twothings);

    setContentView(R.layout.myquick);
    threetimer = new Thread(){

        public void run(){
            try{
             TextView mytxt = (TextView) findViewById(R.id.ses1text);
                mp = MediaPlayer.create(MyQuick.this, R.raw.start);

                mytxt.setText("Let's start in 10 seconds");
                // it works here 

                mp.start();
                sleep(5000);
                mp.release();
                sleep(10000);

 // HERE IS THE PROBLEM

                mp = MediaPlayer.create(MyQuick.this, R.raw.end);

                mytxt.setText("We will now end");
                //it doesn't work here, 
                                    //it closes this portion of the app and goes back to the listview 
                //needless to say the text does not change at all
                mp.start();
                sleep(5000);
                mp.release();


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


            }finally{

                Intent myIntent = new Intent("com.my.quick.MENU");
                startActivity(myIntent);




            }
        }

    };

        threetimer.start();

        }
        }
4

0 に答える 0