私はこのコードを手に入れました:
public void make_square(View v) {
TextView txt_wait = (TextView) findViewById(R.id.square_txt);
txt_wait.setText("wait...");
try{
//rest of the code (scanning a bitmap for pixels)
" make_square
"はonClickイベントです(XMLファイルで)。クリックするとテキストを変更したい(txt_wait
)
次に、変更後、残りのコードを実行する必要があります。しかし、どういうわけかそれは残りのコードを待ち、そのコードが完了すると、彼はtxt_wait
私もこのようなことを試しました(どちらも機能しませんでした):
public void make_square(View v) {
TextView txt_wait = (TextView) findViewById(R.id.square_txt);
txt_wait.setText("wait...");
make_square2(v);
}
public void make_square2(View v){
try{
//rest of the code (scanning a bitmap for pixels)
}
}
しかし今もmake_square2
、テキストを変更する前に最初に実行します。なぜまたはどのようにこれを修正できますか?最初に変更しtxt_wait
、次に変更し、次に残りのコードを変更しますか?
すでにありがとう、Bigflow
編集1:
これを試しました:
public void make_square(final View v) {
TextView txt_wait = (TextView) findViewById(R.id.square_txt);
txt_wait.setText("wait...");
new Thread() {
public void run() {
make_square2(v);
}
}.start();
}
public void make_square2(View v){
try{
//rest of the code
}
}
そしてそれは私のこのエラーを与えます:
E/AndroidRuntime(17487): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
私もこれを試しました:
public void make_square(View v) {
TextView txt_wait = (TextView) findViewById(R.id.square_txt);
txt_wait.setText("wait...");
make_square2(v);
}
public void make_square2(View v)
new Thread() {
public void run() {
//rest of the code
}
}.start();
また、これによりまったく同じエラーが発生します。
私はスレッドの使用に慣れていません。多分私は非常に悪いことをします。もう一度助けていただければ幸いです。