-1

I have an app which displays content of a post while the recycler view is clicked it opens a new activity

        @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);


    }

all i want to acheive is put a progress bar for at least 3 seconds before the other activity is being displayed thanks.

ryda_007
  • 25
  • 1
  • 9

1 Answers1

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);
                    }
                });
            }

  }

I hope it work for you.
Happy Coding.

Arslan Maqbool
  • 519
  • 1
  • 7
  • 21