Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用over gridview时,Progressbar显示错误的进度_Java_Android_Gridview_Android Progressbar - Fatal编程技术网

Java 使用over gridview时,Progressbar显示错误的进度

Java 使用over gridview时,Progressbar显示错误的进度,java,android,gridview,android-progressbar,Java,Android,Gridview,Android Progressbar,ProgressBar状态下的显示有问题。我有一个different image gridview,我想在上面显示进度条状态(不同图像的进度状态不同)。我只是在这里设置如果imagePosition为零,那么状态应该为50,第二个图像我想显示90,第三个图像我想显示10(最大值为100) 所以问题是,第一张和第三张图片显示的进度是100分之90 代码是 class GridAdapter extends BaseAdapter { ArrayList<Topic> topic

ProgressBar状态下的显示有问题。我有一个different image gridview,我想在上面显示进度条状态(不同图像的进度状态不同)。我只是在这里设置如果imagePosition为零,那么状态应该为50,第二个图像我想显示90,第三个图像我想显示10(最大值为100)

所以问题是,第一张和第三张图片显示的进度是100分之90

代码是

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;
    }
}
class GridAdapter扩展了BaseAdapter{
ArrayList主题列表;
语境;
KarnaUtils-utils;
整数宽度;
卡纳克语篇;
ArrayList下载,查看;
没有看到动画;
私人进度律师程序;
int-mProgressStatus=0;
私有处理程序mHandler=新处理程序();
公共GridAdapter(上下文c、ArrayList t、int w){
上下文=c;
主题列表=t;
utils=新的卡纳蒂尔(上下文);
宽度=w;
globals=(KarnaContext)context.getApplicationContext();
downloading=globals.getDownloading_topics();
viewed=globals.getViewedTopics();
not_seen=AnimationUtils.loadAnimation(上下文,R.anim.not_seen);
}
@凌驾
public int getCount(){
返回topicList.size();
}
@凌驾
公共对象getItem(int位置){
返回topicList.get(位置);
}
@凌驾
公共长getItemId(int位置){
返回0;
}
@SuppressLint(“新API”)
@凌驾
公共视图getView(最终整数位置、视图转换视图、视图组父视图){
//System.out.println(“位置为”+位置);
最终视图;
LayoutFlater充气器=(LayoutFlater)context.getSystemService(context.LAYOUT\u充气器\u服务);
if(convertView==null){
视图=充气机。充气(R.layout.category_tile,空);
}否则{
视图=转换视图;
}
topict=topicList.get(位置);
System.out.println(“主题id为”+t.getID());
ImageView=(ImageView)view.findViewById(R.id.category_图标);
setLayoutParams(新的RelativeLayout.LayoutParams(宽度,宽度));
setContentDescription(t.getDescription());
setImageBitmap(utils.getLocalBitmap(t.getName()+“”+t.getID());
ViewAnimator视图\u animator=(ViewAnimator)view.findViewById(R.id.category\u图标\u容器);
if(t.isClicked()){
if(view\u animator.getCurrentView().getId()==R.id.view\u one){
view_animator.showNext();
}
}否则{
if(view\u animator.getCurrentView().getId()==R.id.view\u two){
view_animator.showPrevious();
}
}
布尔值=false;
for(字符串str:下载){
if(t.getID().equalsIgnoreCase(str)){
发现=真;
打破
}
}
如果(找到){
ImageView进度条=(ImageView)view.findViewById(R.id.loading\u image);
进度条设置可见性(视图可见);
AnimationDrawable动画=(AnimationDrawable)进度_bar.getBackground();
animation.start();
if(Integer.valueOf(android.os.Build.VERSION.SDK_INT)<12)
imageView.setAlpha(127);
其他的
imageView.setAlpha(0.5f);
}否则{
boolean topic_viewed=false;
用于(字符串str:已查看){
if(t.getID().equalsIgnoreCase(str)){
topic_view=true;
打破
}
}
ImageView进度条=(ImageView)view.findViewById(R.id.loading\u image);
进度条设置可见性(视图不可见);
mProgress=(ProgressBar)view.findViewById(R.id.progressBar1);
//mpprogress.setProgress(0);
mProgress.setVisibility(View.VISIBLE);
新建异步任务(){
//最终int异常=1,未注册=2,现有=3,无效组织=4;
@凌驾
受保护的void onPreExecute(){
//login.setEnabled(false);
}
@凌驾
受保护的整数doInBackground(字符串…参数){
递增进度条(30);
试一试{
//user=usersdb.queryUserDomain(参数[0],参数[1],参数[2]);
//堆栈加载();
}捕获(例外情况除外){
例如printStackTrace();
//返回异常;
}
返回0;
}
//受保护的void onProgressUpdate(int…progress){
//m进程。设置进程(20);
//                      }
私有void递增进度条(int\u进度){
//最终int进度=_进度;
mHandler.post(新Runnable(){
公开募捐{
//mpprogress.incrementProgressBy(进度);
如果(位置==0)
{
System.out.println(“位置为”+位置);
m进度设置进度(50);
}
如果(位置==1)
{
System.out.println(“位置为”+位置);
m进度。设定进度(10);
}
如果(位置==2)
{
System.out.println(“位置为”+位置);
m进度。设定进度(90);