私のコードは次のとおりです。
public class EventDialog2 extends Dialog implements OnTouchListener{
TextView textv;
Context con;
Thread t;
int flag=0;
public EventDialog2(Context context, int dialogslideanim) {
super(context, dialogslideanim);
con = context;
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog2);
getWindow().setGravity(Gravity.BOTTOM);
timing();
LinearLayout line = (LinearLayout) findViewById(R.id.linear2);
line.setOnTouchListener(this);
line.removeAllViews();
for (int i = 0; i < 15; i++) {
TextView tv = new TextView(con);
tv.setText("TestProcess " + i);
tv.setTextColor(Color.BLACK);
line.addView(tv);
}
}
private void timing() {
// TODO Auto-generated method stub
if(flag==1){
t.stop();
flag=0;
}
t = new Thread(new Runnable() {
public void run() {
try {
t.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dismiss();
}
});
t.start();
}
public boolean onTouch(View v, MotionEvent event) {
System.out.println("touched");
flag=1;
timing();
return false;
}
}
ここで、スレッドは 3 秒後にスリープするため、完全に機能しています。しかし、ダイアログでタッチするとスレッドがリセットされ、タッチから3秒後にスリープする必要があります。私を助けてください。ありがとう