gpt4 book ai didi

java - 图像显示计数器

转载 作者:搜寻专家 更新时间:2023-11-01 09:20:09 26 4
gpt4 key购买 nike

我有一个工作应用程序,其中图像从服务器下载,存储在本地并每隔几秒以幻灯片形式显示在 ImageView 中。我想计算每张图片的显示次数。我不确定如何解决这个问题。我应该制作 6 个计数器(每个图像一个)还是应该创建一个数组来存储图像名称和计数?但是我该如何更新呢?

如有任何帮助或代码 fragment ,我们将不胜感激。

 protected void onPostExecute(String s) {
super.onPostExecute(s);
imageView = findViewById(R.id.imgholder);
Timer mTimer = new Timer();
mTimer.schedule(new TimerTask() {
@Override
public void run() {
// As timer is not a Main/UI thread need to do all UI task on runOnUiThread
DashboardActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
// increase your position so new image will show
position++;
// check whether position increased to length then set it to 0
// so it will show images in circuler
if (position >= 6)
position = 0;
File file = new File(Environment.getExternalStorageDirectory(), user.fullName + "-" + position + ".jpg");
imgUri = Uri.fromFile(file);
Log.v("test", "Now Showing Image: " + imgUri.toString());

// Set Image
imageView.setImageURI(imgUri);
counter++;
Log.v("test","Image: "+ position +" has appeared: " +counter);
}
});
}
}, 0, DELAY_TIMER);

最佳答案

创建一个长度为6的整数数组int[] counters = new int[]{0,0,0,0,0},然后在if(position >= 6) position = 0; 在您的代码中,将计数器递增为 counters[position]++;。因此,您始终可以跟踪数组 counters

中特定位置的图像计数

关于java - 图像显示计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56817854/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com