Guest User

Untitled

a guest
Jan 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. public class Adapter_Usage extends RecyclerView.Adapter<Adapter_Usage.View>{
  2. Context context;
  3. CustomTextView txtsessiontime,txtvolupload,txtvoldownload,txtusageyear,txtusageday,txtusagemon;
  4. ArrayList<Info_Usage> listusage;
  5.  
  6.  
  7. public Adapter_Usage(Context context, int resource, ArrayList<Info_Usage> listusage) {
  8. this.context = context;
  9. this.listusage=listusage;
  10. }
  11. @Override
  12. public View onCreateViewHolder(ViewGroup parent, int viewType) {
  13. android.view.View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_usage, parent, false);
  14. return new View(view);
  15. }
  16.  
  17.  
  18. @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
  19. @Override
  20. public void onBindViewHolder(View holder, int position)
  21. {
  22.  
  23. Info_Usage infousage = listusage.get(holder.getAdapterPosition());
  24. String[] arraybilldate = infousage.strdate.split("\s+");
  25. txtusageyear.setText(arraybilldate[2]);
  26. txtusageday.setText(arraybilldate[1]);
  27. txtusagemon.setText(arraybilldate[0]+", ");
  28. txtsessiontime.setText(infousage.strsessiontime);
  29. txtvolupload.setText("Upload : "+infousage.struploads+" MB");
  30. txtvoldownload.setText("Download : "+infousage.strdownloads+" MB");
  31. }
  32. @Override
  33. public int getItemCount() {
  34. return listusage.size();
  35. }
  36. public class View extends RecyclerView.ViewHolder {
  37.  
  38. public View(android.view.View view) {
  39. super(view);
  40. txtusageyear=view.findViewById(R.id.txtusageyear);
  41. txtusageday=view.findViewById(R.id.txtusageday);
  42. txtusagemon=view.findViewById(R.id.txtusagemon);
  43. txtsessiontime=view.findViewById(R.id.txtsessiontime);
  44. txtvolupload=view.findViewById(R.id.txtvolupload);
  45. txtvoldownload=view.findViewById(R.id.txtvoldownload);
  46. }
  47. }
  48.  
  49. public class Info_Usage {
  50. public String strdate,strdownloads,struploads,strsessiontime,strcurr;
  51.  
  52. public String getDate() {
  53. return strdate;
  54. }
  55. public String getcurr() {
  56. return strcurr;
  57. }
  58.  
  59. Collections.sort(listusage, new Comparator<Info_Usage>()
  60. {
  61. @Override
  62. public int compare(Info_Usage lhs, Info_Usage rhs)
  63. {
  64. int right=Integer.parseInt(rhs.getcurr());
  65. int left=Integer.parseInt(lhs.getcurr());
  66. return right<left?1:right>left?-1:0;
  67. }
  68. });
  69.  
  70. if(listusage.size()==0)
  71. {
  72. recycler.setVisibility(View.GONE);
  73. txtnousage.setVisibility(View.VISIBLE);
  74. }
  75. else
  76. {
  77.  
  78. txtnousage.setVisibility(View.GONE);
  79. recycler.setVisibility(View.VISIBLE);
  80. recycler.setAdapter(new Adapter_Usage(Activity_Usage.this, 0, listusage));
  81. }
Add Comment
Please, Sign In to add comment