how do I implement progress bar outside of the rec

2020-07-25 10:42发布

问题:

I want to display something like this-->My Home activity..inside Whats Android,Start learning ,Get ahead there are recycleviews like this-->enter image description here

how do I implement this kind of progressbar based upon users reading??

My Home activity:

public class MainActivity extends AppCompatActivity {

private RecyclerView recyclerview ;
private String[] names ;
private TypedArray profile_pics ;
private TypedArray card_images;
 ImageView imageView;

private List<Member> memberList ;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super .onCreate(savedInstanceState);
    setContentView(R.layout. activity_main );
    imageView=findViewById(R.id.search);

   Toolbar toolbar = (Toolbar) findViewById(R.id. toolbar );
   setSupportActionBar( toolbar );
    names = getResources().getStringArray(R.array. names );
    profile_pics = getResources().obtainTypedArray(R.array. profile_pics );
    card_images=getResources().obtainTypedArray(R.array.card_images);
    memberList = new ArrayList<>();
    for (int i = 0; i < names.length; i++) {
        Member member = new Member( names [i], profile_pics .getResourceId(i, -1),card_images.getResourceId(i,-1));
        memberList .add( member );
    }
    recyclerview = (RecyclerView) findViewById(R.id. recyclerview );
    LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this);
    recyclerview.setLayoutManager( layoutManager );
    MainAdapter adapter = new MainAdapter(memberList, MainActivity.this);
    recyclerview .setAdapter( adapter );
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent=new Intent(getApplicationContext(),Search.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            getApplicationContext().startActivity(intent);
        }
    });}}

home activity adapter:

public class MainAdapter extends RecyclerView.Adapter<MainAdapter.MemberViewHolder> {
private List<Member> members ;
private Context context ;
public MainAdapter(List<Member> members , Context context ) {
    this. members = members;
    this. context = context;
}
public class MemberViewHolder extends RecyclerView.ViewHolder {
    private CardView cardView ;
    private TextView name_tv ;
    private ImageView email_tv ;
    private ImageView pic_iv ;
    public MemberViewHolder(View itemView) {
        super (itemView);
        cardView = (CardView) itemView.findViewById(R.id. cv );
        name_tv = (TextView) itemView.findViewById(R.id. member_name );
        email_tv=(ImageView) itemView.findViewById(R.id.thumbnail);
        pic_iv = (ImageView) itemView.findViewById(R.id. profile_pic );
    }
  }

@Override
public void onBindViewHolder(MemberViewHolder memberViewHolder, int i) {
    final int pos = i;
    memberViewHolder. name_tv .setText(members.get(i).getName());
    memberViewHolder.email_tv.setImageResource(members.get(i).getCards());
    memberViewHolder. pic_iv .setImageResource(members.get(i).getPhotoID());
    memberViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(pos == 0){
                view.getContext().startActivity(new Intent(view.getContext(), Introduction.class));
            }

            else if(pos == 1){
                view.getContext().startActivity(new Intent(view.getContext(), WhatsAndroid.class));
            }

            else if(pos == 2){
                view.getContext().startActivity(new Intent(view.getContext(), StartLearning.class));
            }
            else if(pos == 3){
                view.getContext().startActivity(new Intent(view.getContext(), GetAhead.class));
            }

            else if(pos == 4){
                view.getContext().startActivity(new Intent(view.getContext(), TipsandTricks.class));
            }
            else if (pos==5)
            {
                view.getContext().startActivity(new Intent(view.getContext(), Interview.class));

            }
        }
    });
}
@Override
public MemberViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout. cardview_row_item , viewGroup, false);
    MemberViewHolder memberViewHolder = new MemberViewHolder(view);
    return memberViewHolder;
}
@Override
public int getItemCount() {
    return members.size();
 }
}

taking one of view of home (Start learning activity) which is loading a retrofit data:

public class StartLearning extends AppCompatActivity {
private RecyclerView recyclerView;
private SLAdapter slAdapter;
ProgressDialog progressDialog;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.startlearning_layout);
    progressDialog = new ProgressDialog(StartLearning.this);
    progressDialog.setMessage("Loading....");
    progressDialog.show();
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        /*Create handle for the RetrofitInstance interface*/
        SLApiSevice service = SLApiClient.getRetrofitInstance().create(SLApiSevice.class);
        Call<List<SlModel>> call = service.getMySlmodel();

        call.enqueue(new Callback<List<SlModel>>() {
            @Override
            public void onResponse(Call<List<SlModel>> call, Response<List<SlModel>> response) {
                progressDialog.dismiss();
                generateDataList(response.body());

            }

            @Override
            public void onFailure(Call<List<SlModel>> call, Throwable t) {
                progressDialog.dismiss();
                Toast.makeText(getApplicationContext(), "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();


            }
        });
    }
}
private void generateDataList(List<SlModel> employeeList) {
    recyclerView = findViewById(R.id.SLrecycle);
    LinearLayoutManager manager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(manager);
    recyclerView.setHasFixedSize(true);
    slAdapter = new SLAdapter(getApplicationContext(),employeeList);
    recyclerView.setAdapter(slAdapter);
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        finish();
    }
    return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed() {
    super.onBackPressed();
}

start learning adapter :

public class SLAdapter extends RecyclerView.Adapter<SLAdapter.CustomViewHolder> {

List<StartLearning.SlModel> Slmdel;
Context context;

public SLAdapter(Context context,List<StartLearning.SlModel> employees) {
    this.Slmdel = employees;
    this.context=context;
}

@Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.startlearning_item, parent, false);

    return new CustomViewHolder(itemView);
}

@Override
public void onBindViewHolder(CustomViewHolder holder, int position) {
    // TipsModel employee = employees.get(position);
    //// holder.employeeName.setText(employees.get(position).getTips());
    holder.textView.setText(String.valueOf(position+1)+". ");
    holder.employeeName.setText(Slmdel.get(position).getTitle());


}

@Override
public int getItemCount() {
    return Slmdel.size();
    //return (employees == null) ? 0 : employees.size();

}

public class CustomViewHolder extends RecyclerView.ViewHolder {
    public TextView employeeName;
    TextView textView;

    public CustomViewHolder(View view) {
        super(view);
        employeeName = (TextView) view.findViewById(R.id.Sl2);
        textView=view.findViewById(R.id.Sl1);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =  new Intent(context, NextSLactivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("title", Slmdel.get(getAdapterPosition()).getTitle());
               intent.putExtra("idSLnext", Slmdel.get(getAdapterPosition()).getId());
                //Log.e("ashwini",WAmdel.get(getAdapterPosition()).getId());
                context.startActivity(intent);

            }
        });


    }
  }
}

回答1:

first change your Adapter CardView Item to include this CircleProgressBar and then for each item you can set your progress level



回答2:

First you need to get Data but as this question is regarding showing circular progressbar with perentage here is how you can do it

1.Creating drawable resource file Create one drawable resource file named circular.xml (drawable resource file means in android studio project’s file structure, you will find a folder named drawable inside a res folder as shown in the below image.)

2.Coding circular.xml Copy and paste following code into circular.xml

Code

....

rather writing same i recommend check this out https://demonuts.com/circular-progress-bar/