单击回收器视图时显示进度条

时间:2017-04-15 01:39:20

标签: android json android-recyclerview

我有一个应用程序,显示帖子的内容,同时点击回收者视图,它会打开一个新的活动

        @Override
    public void onClick(View v) {

        int position = getAdapterPosition();
        FeedItem feeditem = this.feeditem.get(position);
        Intent intent = new Intent(this.ctx, ContentActivity.class);
        intent.putExtra("posturl", feeditem.getPostUrl());
        intent.putExtra("Author",feeditem.getAuthorname());
        intent.putExtra("excerpt",feeditem.getExcerpt());
        intent.putExtra("content",feeditem.getContent());
        intent.putExtra("title",feeditem.getTitle());
        intent.putExtra("date",feeditem.getdate());
        intent.putExtra("thumbnail",feeditem.getAttachmentUrl());
        this.ctx.startActivity(intent);


    }

所有我想要实现的是在显示其他活动之前至少3秒进度栏谢谢。

1 个答案:

答案 0 :(得分:0)

Intent intent;  //declare global 
ProgressDialog progress; //declare global because before start activity dismiss the dialog
 @Override
    public void onClick(View v) {

        int position = getAdapterPosition();
        FeedItem feeditem = this.feeditem.get(position);
         intent = new Intent(this.ctx, ContentActivity.class);
        intent.putExtra("posturl", feeditem.getPostUrl());
        intent.putExtra("Author",feeditem.getAuthorname());
        intent.putExtra("excerpt",feeditem.getExcerpt());
        intent.putExtra("content",feeditem.getContent());
        intent.putExtra("title",feeditem.getTitle());
        intent.putExtra("date",feeditem.getdate());
        intent.putExtra("thumbnail",feeditem.getAttachmentUrl());

//here start the progress bar

        progress = new ProgressDialog(this);
        progress.setMessage("Loading...");
        progress.setCancelable(false);
        progress.show();

        //set the timer here for 3 second
        Timer t = new Timer();
        t.schedule(new waitingtimer(), 3000);

    }


    //here is the class of timer
    private class waitingtimer extends TimerTask {
            @Override
            public void run() {

                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {

                        progress.dismiss();
                        //here start the activity
                        this.ctx.startActivity(intent);
                    }
                });
            }

  }

我希望它适合你。
快乐的编码。