CustomListRowAdapter.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package epson.common;
  2. import android.content.Context;
  3. import android.view.LayoutInflater;
  4. import android.view.View;
  5. import android.view.ViewGroup;
  6. import android.widget.ArrayAdapter;
  7. import android.widget.ImageView;
  8. import android.widget.LinearLayout;
  9. import android.widget.TextView;
  10. import epson.print.C2135R;
  11. import epson.print.Util.EPLog;
  12. import java.util.List;
  13. public class CustomListRowAdapter extends ArrayAdapter<CustomListRow> {
  14. private static final String TAG = "Hoge";
  15. private LayoutInflater inflater;
  16. private List<CustomListRow> items;
  17. private View.OnClickListener listener;
  18. private int resourceId;
  19. public CustomListRowAdapter(Context context, int i, List<CustomListRow> list) {
  20. this(context, i, list, (View.OnClickListener) null);
  21. }
  22. public CustomListRowAdapter(Context context, int i, List<CustomListRow> list, View.OnClickListener onClickListener) {
  23. super(context, i, list);
  24. this.resourceId = i;
  25. this.items = list;
  26. this.inflater = (LayoutInflater) context.getSystemService("layout_inflater");
  27. this.listener = onClickListener;
  28. }
  29. public View getView(int i, View view, ViewGroup viewGroup) {
  30. if (view == null) {
  31. view = this.inflater.inflate(this.resourceId, (ViewGroup) null);
  32. }
  33. return populateView(i, view, viewGroup);
  34. }
  35. protected View populateView(int i, View view, ViewGroup viewGroup) {
  36. EPLog.m305d(TAG, "View position [" + i + "]");
  37. CustomListRow customListRow = this.items.get(i);
  38. if (customListRow.getPrefixImageId() != null) {
  39. ((ImageView) view.findViewById(R.C2137id.row_prefix_image)).setImageResource(customListRow.getPrefixImageId().intValue());
  40. }
  41. if (customListRow.getSuffixImageId() != null) {
  42. ((ImageView) view.findViewById(R.C2137id.row_suffix_image)).setImageResource(customListRow.getSuffixImageId().intValue());
  43. }
  44. LinearLayout linearLayout = (LinearLayout) view.findViewById(R.C2137id.row_list_area);
  45. linearLayout.removeAllViews();
  46. int sieze = customListRow.sieze();
  47. for (int i2 = 0; i2 < sieze; i2++) {
  48. TextView textView = new TextView(viewGroup.getContext());
  49. textView.setText(customListRow.getText(i2));
  50. if (customListRow.getTextSize(i2) > 1.0f) {
  51. textView.setTextSize(customListRow.getTextSize(i2));
  52. }
  53. linearLayout.addView(textView, i2);
  54. }
  55. View.OnClickListener onClickListener = this.listener;
  56. if (onClickListener != null) {
  57. view.setOnClickListener(onClickListener);
  58. }
  59. return view;
  60. }
  61. public void addList(CustomListRow customListRow) {
  62. this.items.add(customListRow);
  63. }
  64. public void setList(int i, CustomListRow customListRow) {
  65. this.items.set(i, customListRow);
  66. }
  67. }