我的警告对话框会弹出27次。我有实现处理程序,在处理程序中,我使用CountDownTimer。警报对话框代码在CountDownTimer的onFinish上。以下是我的代码。
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.face_detect_surface_view);
mOpenCvCameraView = (Tutorial3View) findViewById(R.id.tutorial3_activity_java_surface_view);
mOpenCvCameraView.setCvCameraViewListener(this);
mPath=getFilesDir()+"/facerecogOCV/";
labelsFile= new labels(mPath);
Iv=(ImageView)findViewById(R.id.imageView1);
textresult = (TextView) findViewById(R.id.textView1);
mHandler = new Handler() {
@Override
public void handleMessage( Message msg) {
Log.e("X", (String) msg.obj);
if (msg.obj=="IMG")
{
Canvas canvas = new Canvas();
canvas.setBitmap(mBitmap);
Iv.setImageBitmap(mBitmap);
if (countImages>=MAXIMG-1)
{
toggleButtonGrabar.setChecked(false);
grabarOnclick();
}
}
else
{
textresult.setText(msg.obj.toString());
textpercent.setVisibility(View.VISIBLE);
textpercent.setText( mLikely + "%");
new CountDownTimer(5000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
mOpenCvCameraView.enableView();
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
final AlertDialog ad = new AlertDialog.Builder(FdActivity.this).create();
ad.setTitle("Recognition Status");
ad.setMessage("Criminal ID :" + textresult.getText().toString() + "\nSimilarities : " + textpercent.getText().toString() );
ad.setButton("Rescan", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),
"Rescanning", Toast.LENGTH_SHORT).show();
Bundle configBundle = new Bundle();
onCreate(configBundle);
mOpenCvCameraView.enableView();
}
});
ad.show();//pops out 27 times
mOpenCvCameraView.disableView();
buttonSearch.setChecked(false);
}
}.start();
}
}
};
text=(EditText)findViewById(R.id.editText1);
buttonCatalog=(Button)findViewById(R.id.buttonCat);
toggleButtonGrabar=(ToggleButton)findViewById(R.id.toggleButtonGrabar);
buttonSearch=(ToggleButton)findViewById(R.id.buttonBuscar);
toggleButtonTrain=(ToggleButton)findViewById(R.id.toggleButton1);
textState= (TextView)findViewById(R.id.textViewState);
textpercent = (TextView)findViewById(R.id.textViewpercent);
imCamera=(ImageButton)findViewById(R.id.imageButton1);
textpercent.setVisibility(View.INVISIBLE);
text.setVisibility(View.INVISIBLE);
textresult.setVisibility(View.INVISIBLE);
toggleButtonGrabar.setVisibility(View.INVISIBLE);
text.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((text.getText().toString().length()>0)&&(toggleButtonTrain.isChecked()))
toggleButtonGrabar.setVisibility(View.VISIBLE);
else
toggleButtonGrabar.setVisibility(View.INVISIBLE);
return false;
}
});
toggleButtonTrain.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (toggleButtonTrain.isChecked()) {
textState.setText(getResources().getString(R.string.SEnter));
buttonSearch.setVisibility(View.INVISIBLE);
textresult.setVisibility(View.VISIBLE);
text.setVisibility(View.VISIBLE);
textresult.setText(getResources().getString(R.string.SFaceName));
if (text.getText().toString().length() > 0)
toggleButtonGrabar.setVisibility(View.VISIBLE);
textpercent.setVisibility(View.INVISIBLE);
} else {
textState.setText(R.string.Straininig);
textresult.setText("");
text.setVisibility(View.INVISIBLE);
buttonSearch.setVisibility(View.VISIBLE);
;
textresult.setText("");
{
toggleButtonGrabar.setVisibility(View.INVISIBLE);
text.setVisibility(View.INVISIBLE);
}
Toast.makeText(getApplicationContext(), getResources().getString(R.string.Straininig), Toast.LENGTH_LONG).show();
fr.train();
textState.setText(getResources().getString(R.string.BLANK));
}
}
});
toggleButtonGrabar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
grabarOnclick();
}
});
imCamera.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (mChooseCamera==frontCam)
{
mChooseCamera=backCam;
mOpenCvCameraView.setCamBack();
}
else
{
mChooseCamera=frontCam;
mOpenCvCameraView.setCamFront();
}
}
});
buttonSearch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (buttonSearch.isChecked())
{
if (!fr.canPredict())
{
buttonSearch.setChecked(false);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.SCanntoPredic), Toast.LENGTH_LONG).show();
return;
}
textState.setText(getResources().getString(R.string.SSearching));
toggleButtonGrabar.setVisibility(View.INVISIBLE);
toggleButtonTrain.setVisibility(View.INVISIBLE);
text.setVisibility(View.INVISIBLE);
faceState=SEARCHING;
textresult.setVisibility(View.VISIBLE);
}
else
{
faceState=IDLE;
textState.setText(getResources().getString(R.string.SIdle));
toggleButtonGrabar.setVisibility(View.INVISIBLE);
toggleButtonTrain.setVisibility(View.VISIBLE);
text.setVisibility(View.INVISIBLE);
textresult.setVisibility(View.INVISIBLE);
}
}
});
boolean success=(new File(mPath)).mkdirs();
if (!success)
{
Log.e("Error", "Error creating directory");
}
}
有人请帮我解决这个问题。我仍然是Android编程的学习者。我不知道如何解决这个问题。
由于
答案 0 :(得分:0)
我认为你的处理程序传递了大量的消息。您可以使用
验证Log.e("X", msg.obj);
并检查logcat的输出。