ca261e4f9c65b30fdf87d56ce15d5ccc9c791487.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package eVVM.apk.common;
  2. import android.content.Context;
  3. import android.support.annotation.ColorInt;
  4. import android.support.annotation.DrawableRes;
  5. import android.support.annotation.IdRes;
  6. import android.support.annotation.StringRes;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.CompoundButton;
  10. import android.widget.ImageView;
  11. import android.widget.TextView;
  12. import com.hjq.base.BaseListViewAdapter;
  13. import com.hjq.image.ImageLoader;
  14. import butterknife.ButterKnife;
  15. public abstract class MyListViewAdapter<T, VH extends MyListViewAdapter.ViewHolder>
  16. extends BaseListViewAdapter<T, VH> {
  17. //当前列表的页码,默认为第一页,用于分页加载功能
  18. private int mPageNumber = 1;
  19. //是否是最后一页,默认为false,用于分页加载功能
  20. private boolean mLastPage;
  21. //标记对象
  22. private Object mTag;
  23. public MyListViewAdapter(Context context) {
  24. super(context);
  25. }
  26. /**
  27. * 获取当前的页码
  28. */
  29. public int getPageNumber() {
  30. return mPageNumber;
  31. }
  32. /**
  33. * 设置当前的页码
  34. */
  35. public void setPageNumber(int pageNumber) {
  36. mPageNumber = pageNumber;
  37. }
  38. /**
  39. * 当前是否为最后一页
  40. */
  41. public boolean isLastPage() {
  42. return mLastPage;
  43. }
  44. /**
  45. * 设置是否为最后一页
  46. */
  47. public void setLastPage(boolean lastPage) {
  48. mLastPage = lastPage;
  49. }
  50. /**
  51. * 获取标记
  52. */
  53. public Object getTag() {
  54. return mTag;
  55. }
  56. /**
  57. * 设置标记
  58. */
  59. public void setTag(Object tag) {
  60. mTag = tag;
  61. }
  62. public class ViewHolder extends BaseListViewAdapter.ViewHolder {
  63. public ViewHolder(ViewGroup parent, int layoutId) {
  64. super(parent, layoutId);
  65. }
  66. public ViewHolder(View itemView) {
  67. super(itemView);
  68. ButterKnife.bind(itemView);
  69. }
  70. public final ViewHolder setText(@IdRes int viewId, @StringRes int resId) {
  71. return setText(viewId, getItemView().getResources().getString(resId));
  72. }
  73. public final ViewHolder setText(@IdRes int viewId, String text) {
  74. if (text == null) text = "";
  75. View view = findViewById(viewId);
  76. if (view instanceof TextView) {
  77. ((TextView) view).setText(text);
  78. }
  79. return this;
  80. }
  81. public final ViewHolder setVisibility(@IdRes int viewId, int visibility) {
  82. View view = findViewById(viewId);
  83. if (view != null) {
  84. view.setVisibility(visibility);
  85. }
  86. return this;
  87. }
  88. public final ViewHolder setColor(@IdRes int viewId, @ColorInt int color) {
  89. View view = findViewById(viewId);
  90. if (view instanceof TextView) {
  91. ((TextView) view).setTextColor(color);
  92. }
  93. return this;
  94. }
  95. public final ViewHolder setImage(@IdRes int viewId, @DrawableRes int resId) {
  96. View view = findViewById(viewId);
  97. if (view instanceof ImageView) {
  98. ((ImageView) view).setImageResource(resId);
  99. }
  100. return this;
  101. }
  102. public final ViewHolder setImage(@IdRes int viewId, String url) {
  103. View view = findViewById(viewId);
  104. if (view instanceof ImageView) {
  105. ImageLoader.loadImage((ImageView) view, url);
  106. }
  107. return this;
  108. }
  109. public final ViewHolder setChecked(@IdRes int viewId, boolean checked) {
  110. View view = findViewById(viewId);
  111. if (view instanceof CompoundButton) {
  112. ((CompoundButton) view).setChecked(checked);
  113. }
  114. return this;
  115. }
  116. }
  117. }