CustomListRowAdapter.java 2.8 KB

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