Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Adapter_Usage extends RecyclerView.Adapter<Adapter_Usage.View>{
- Context context;
- CustomTextView txtsessiontime,txtvolupload,txtvoldownload,txtusageyear,txtusageday,txtusagemon;
- ArrayList<Info_Usage> listusage;
- public Adapter_Usage(Context context, int resource, ArrayList<Info_Usage> listusage) {
- this.context = context;
- this.listusage=listusage;
- }
- @Override
- public View onCreateViewHolder(ViewGroup parent, int viewType) {
- android.view.View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_usage, parent, false);
- return new View(view);
- }
- @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
- @Override
- public void onBindViewHolder(View holder, int position)
- {
- Info_Usage infousage = listusage.get(holder.getAdapterPosition());
- String[] arraybilldate = infousage.strdate.split("\s+");
- txtusageyear.setText(arraybilldate[2]);
- txtusageday.setText(arraybilldate[1]);
- txtusagemon.setText(arraybilldate[0]+", ");
- txtsessiontime.setText(infousage.strsessiontime);
- txtvolupload.setText("Upload : "+infousage.struploads+" MB");
- txtvoldownload.setText("Download : "+infousage.strdownloads+" MB");
- }
- @Override
- public int getItemCount() {
- return listusage.size();
- }
- public class View extends RecyclerView.ViewHolder {
- public View(android.view.View view) {
- super(view);
- txtusageyear=view.findViewById(R.id.txtusageyear);
- txtusageday=view.findViewById(R.id.txtusageday);
- txtusagemon=view.findViewById(R.id.txtusagemon);
- txtsessiontime=view.findViewById(R.id.txtsessiontime);
- txtvolupload=view.findViewById(R.id.txtvolupload);
- txtvoldownload=view.findViewById(R.id.txtvoldownload);
- }
- }
- public class Info_Usage {
- public String strdate,strdownloads,struploads,strsessiontime,strcurr;
- public String getDate() {
- return strdate;
- }
- public String getcurr() {
- return strcurr;
- }
- Collections.sort(listusage, new Comparator<Info_Usage>()
- {
- @Override
- public int compare(Info_Usage lhs, Info_Usage rhs)
- {
- int right=Integer.parseInt(rhs.getcurr());
- int left=Integer.parseInt(lhs.getcurr());
- return right<left?1:right>left?-1:0;
- }
- });
- if(listusage.size()==0)
- {
- recycler.setVisibility(View.GONE);
- txtnousage.setVisibility(View.VISIBLE);
- }
- else
- {
- txtnousage.setVisibility(View.GONE);
- recycler.setVisibility(View.VISIBLE);
- recycler.setAdapter(new Adapter_Usage(Activity_Usage.this, 0, listusage));
- }
Add Comment
Please, Sign In to add comment