Posted By


ximiboy on 10/11/12

Tagged


Statistics


Viewed 147 times
Favorited by 0 user(s)

Adapter BaseAdapter


/ Published in: Java
Save to your folder(s)

Adaptador de una lista


Copy this code and paste it in your HTML
  1. /**
  2.  * Adapter of the list X
  3.  *
  4.  */
  5. public class AdapterListX extends BaseAdapter {
  6. private LayoutInflater mInflater;
  7. private ActivityMain c;
  8.  
  9. /**
  10. * AdapterListX: Constructor
  11. *
  12. * @param context
  13. */
  14. public AdapterListX (ActivityMain context) {
  15. c = context;
  16. mInflater = LayoutInflater.from(c);
  17. }
  18.  
  19. /**
  20. * getView: Inits the view of a row
  21. *
  22. */
  23. public View getView(final int position, View convertView, ViewGroup parent) {
  24. TextView text1, text2;
  25.  
  26. if (convertView == null) {
  27. convertView = mInflater
  28. .inflate(R.layout.listview_x, null);
  29. convertView.setOnClickListener(new OnClickListener() {
  30. public void onClick(View v) {
  31. onClickRow(position);
  32. }
  33. });
  34. } else {
  35. convertView.setOnClickListener(new OnClickListener() {
  36. public void onClick(View v) {
  37. onClickRow(position);
  38. }
  39. });
  40. }
  41.  
  42. text1 = (TextView) convertView.findViewById(R.id.Text1);
  43. text2 = (TextView) convertView.findViewById(R.id.Text2);
  44.  
  45. text1.setText("");
  46. text2.setText("");
  47.  
  48. return convertView;
  49. }
  50.  
  51. /**
  52. * onClickRow: Controls the event of clicking a row
  53. * @param pos
  54. */
  55. private void onClickRow(int pos) {
  56. notifyDataSetChanged();
  57. }
  58.  
  59. /**
  60. * getCount: Gets the number of rows.
  61. */
  62. public int getCount() {
  63. return cursor.getCount();
  64. }
  65.  
  66. public Object getItem(int position) {
  67. return position;
  68. }
  69.  
  70. public long getItemId(int position) {
  71. return 0;
  72. }
  73. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.