我希望在特定的时间段内保持for循环。
我正在使用Thread.Sleep(duration)
但这是错误的。
请让我知道这个问题的任何解决方案。提前感谢您的建议。如果有任何疑虑,请告诉我。
答案 0 :(得分:4)
试试这个:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//write here your code
}
}, 5000);
答案 1 :(得分:1)
您可以使用 Handler
for (int i = 0; i<50 ;i++) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// perform your task here
}
}, 1000 );// delay time in miniseonds
}
答案 2 :(得分:0)
要在特定时间内保留Mat img1 = new Mat();
Mat img2 = new Mat();
Utils.bitmapToMat(bmpimg1, img1);
Utils.bitmapToMat(bmpimg2, img2);
FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor descriptor = DescriptorExtractor.create(DescriptorExtractor.ORB);;
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
// First photo
Imgproc.cvtColor(img1, img1, Imgproc.COLOR_RGB2GRAY);
Mat descriptors1 = new Mat();
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
detector.detect(img1, keypoints1);
descriptor.compute(img1, keypoints1, descriptors1);
// Second photo
Imgproc.cvtColor(img2, img2, Imgproc.COLOR_RGB2GRAY);
Mat descriptors2 = new Mat();
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
detector.detect(img2, keypoints2);
descriptor.compute(img2, keypoints2, descriptors2);
// Matching
MatOfDMatch matches = new MatOfDMatch();
MatOfDMatch filteredMatches = new MatOfDMatch();
matcher.match(descriptors1, descriptors2, matches);
List<DMatch> matchesList = matches.toList();
Double max_dist = 0.0;
Double min_dist = 100.0;
for(int i = 0;i < matchesList.size(); i++){
Double dist = (double) matchesList.get(i).distance;
if (dist < min_dist)
min_dist = dist;
if ( dist > max_dist)
max_dist = dist;
}
LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
for(int i = 0;i < matchesList.size(); i++){
Log.d("LOG!",(" : matchesList.get(i).distance :" + matchesList.get(i).distance));
Log.d("LOG!",(" : 1.5 * min_dist :" + min_dist));
if (matchesList.get(i).distance <= 1.5 * min_dist)
good_matches.addLast(matchesList.get(i));
}
MatOfDMatch goodMatches = new MatOfDMatch();
goodMatches.fromList(good_matches);
List<DMatch> bestMatches=goodMatches.toList();
Collections.sort(bestMatches,new Comparator<DMatch>() {
@Override
public int compare(DMatch o1, DMatch o2) {
if(o1.distance<o2.distance)
return -1;
if(o1.distance>o2.distance)
return 1;
else {
Log.d("LOG!",("Equal i value: "));
return 0;
}
}
});
Log.d("LOG!",("bestMatches.size() : "+bestMatches.size() + " : goodMatches size :" + goodMatches.toList().size()));
:只需复制上述代码段,然后尝试更改毫秒 1秒= 1000毫秒
for loot
答案 3 :(得分:0)
for (int i = 0; i < arrayList.size(); i++)
{
View view = listview.getChildAt(i);
CheckBox dateChk = view.findViewById(R.id.chkDate);
if(dateChk.isChecked())
{
File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + arrayList.get(i).getfilename());
if (f != null && f.exists())
{
f.delete();
}
}
}