gpt4 book ai didi

java - 使用 gridview 时进度条显示错误的进度

转载 作者:行者123 更新时间:2023-11-29 05:33:42 28 4
gpt4 key购买 nike

ProgressBar状态显示有问题。我有不同的图像 gridview,我想在其上显示进度条状态(不同图像的不同进度状态)。我只是在这里设置,如果 imagePosition 为零,则状态应为 50,在第二张图像上我想显示 90,在第三张图像上图片我想显示 10(最大值为 100)。

所以问题是它在第一张和第三张图片中显示 90% 的进度(满分 100)。

代码是

class GridAdapter extends BaseAdapter {
ArrayList<Topic> topicList;
Context context;
KarnaUtils utils;
int width;
KarnaContext globals;
ArrayList<String> downloading, viewed;
Animation not_seen;
private ProgressBar mProgress;
int mProgressStatus = 0;
private Handler mHandler = new Handler();
public GridAdapter(Context c, ArrayList<Topic> t, int w) {
context = c;
topicList = t;
utils = new KarnaUtils(context);
width = w;
globals = (KarnaContext) context.getApplicationContext();
downloading = globals.getDownloading_topics();
viewed = globals.getViewedTopics();
not_seen = AnimationUtils.loadAnimation(context, R.anim.not_seen);
}

@Override
public int getCount() {
return topicList.size();
}

@Override
public Object getItem(int position) {
return topicList.get(position);
}

@Override
public long getItemId(int position) {
return 0;
}

@SuppressLint("NewApi")
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// System.out.println("the position is"+position);
final View view;
LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
view = inflator.inflate(R.layout.category_tile, null);
} else {
view = convertView;
}

Topic t = topicList.get(position);
System.out.println("the topic id is"+t.getID());
ImageView imageView = (ImageView) view.findViewById(R.id.category_icon);
imageView.setLayoutParams(new RelativeLayout.LayoutParams(width, width));
imageView.setContentDescription(t.getDescription());
imageView.setImageBitmap(utils.getLocalBitmap(t.getName() + "_" + t.getID()));

ViewAnimator view_animator = (ViewAnimator) view.findViewById(R.id.category_icon_container);

if (t.isClicked()) {
if (view_animator.getCurrentView().getId() == R.id.view_one) {
view_animator.showNext();
}
} else {
if (view_animator.getCurrentView().getId() == R.id.view_two) {
view_animator.showPrevious();
}
}

boolean found = false;
for (String str : downloading) {
if (t.getID().equalsIgnoreCase(str)) {
found = true;
break;
}
}

if (found) {
ImageView progress_bar = (ImageView) view.findViewById(R.id.loading_image);
progress_bar.setVisibility(View.VISIBLE);
AnimationDrawable animation = (AnimationDrawable) progress_bar.getBackground();
animation.start();
if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) < 12)
imageView.setAlpha(127);
else
imageView.setAlpha(0.5f);
} else {

boolean topic_viewed = false;
for (String str : viewed) {
if (t.getID().equalsIgnoreCase(str)) {
topic_viewed = true;
break;
}
}

ImageView progress_bar = (ImageView) view.findViewById(R.id.loading_image);
progress_bar.setVisibility(View.INVISIBLE);


mProgress=(ProgressBar) view.findViewById(R.id.progressBar1);
// mProgress.setProgress(0);

mProgress.setVisibility(View.VISIBLE);




new AsyncTask<String, Void, Integer>() {
//final int EXCEPTION = 1, NOT_REGISTERED = 2, EXISTING = 3, INVALID_ORG = 4;

@Override
protected void onPreExecute() {
//login.setEnabled(false);
}

@Override
protected Integer doInBackground(String... params) {

incrementProgressBar(30);


try {
//user = usersdb.queryUserDomain(params[0], params[1], params[2]);
//stackmobLoading();

} catch (Exception ex) {
ex.printStackTrace();
//return EXCEPTION;
}

return 0;
}
// protected void onProgressUpdate(int... progress) {
// mProgress.setProgress(20);
// }

private void incrementProgressBar(int _progress) {
//final int progress = _progress;
mHandler.post(new Runnable() {
public void run() {
//mProgress.incrementProgressBy(progress);

if(position==0)
{
System.out.println("The postion is"+position);

mProgress.setProgress(50);
}
if(position==1)
{
System.out.println("The postion is"+position);
mProgress.setProgress(10);
}
if(position==2)
{
System.out.println("The postion is"+position);
mProgress.setProgress(90);
}


}
});
}


}.execute(t.getID());



if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) < 12)
imageView.setAlpha(255);
else
imageView.setAlpha(1.0f);

/*if (!topic_viewed) {
imageView.setAnimation(not_seen);
not_seen.start();
} else {
not_seen.cancel();
}*/
}

return view;
}
}

enter image description here

为什么缺少第二个进度。如果我要添加一个或多个图像,则进度条仅显示第一张和最后一张图像。

最佳答案

我找到了它的解决方案。我只是使用了为每个位置创建的最终对象。(final ProgressBar= new ProgressBar();)。早些时候它是在 Activity 启动时创建的,因此对象不能一次保存多个值。所以它只持有一个值(无论如何都是最后一个)。但是当我在 getView 中创建对象时,它每次都会为每个设置值的位置创建一个最终对象。它对我来说很好..但非常感谢你们试图帮助我。如果答案对你来说也很满意,请投票。

关于java - 使用 gridview 时进度条显示错误的进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20237754/

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