Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. import android.app.Activity;
  2. import android.content.Context;
  3. import android.graphics.Bitmap;
  4. import android.graphics.BitmapFactory;
  5. import android.view.LayoutInflater;
  6. import android.view.View;
  7. import android.view.ViewGroup;
  8. import android.widget.ArrayAdapter;
  9. import android.widget.BaseAdapter;
  10. import android.widget.ImageView;
  11. import android.widget.TextView;
  12. import com.example.rama.hello.Bean.RowItem;
  13. import com.example.rama.hello.R;
  14.  
  15. import java.io.File;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18.  
  19. /**
  20. * Created by RAMA on 10/25/2016.
  21. */
  22. public class CustomAdapter extends ArrayAdapter<RowItem> {
  23.  
  24. Context mcontext;
  25. ArrayList<RowItem> rowItem = new ArrayList<RowItem>();
  26. private RowItem row;
  27. RowItem data;
  28.  
  29.  
  30. public CustomAdapter(Context context, int resourceId,
  31. ArrayList<RowItem> items) {
  32. super(context, resourceId, items);
  33. this.mcontext = context;
  34. }
  35.  
  36. @Override
  37. public int getCount()
  38. {
  39. return rowItem.size();
  40. }
  41.  
  42.  
  43. @Override
  44. public long getItemId(int position) {
  45. return rowItem.indexOf(getItem(position));
  46. }
  47.  
  48. @Override
  49. public View getView(int position, View convertView, ViewGroup parent)
  50. {
  51. if (convertView == null)
  52. {
  53. LayoutInflater mInflater = (LayoutInflater) mcontext
  54. .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
  55. convertView = mInflater.inflate(R.layout.list_item,parent,false);
  56. }
  57.  
  58. ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
  59. TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
  60. TextView txtSubTitle = (TextView) convertView.findViewById(R.id.sub_title);
  61. TextView txtRightTitle = (TextView) convertView.findViewById(R.id.right_title);
  62.  
  63. RowItem row_pos = getItem(position);
  64.  
  65. // setting the image resource and title,subtitle,Righttitle
  66. File imgFile = new File(row_pos.getIcon());
  67.  
  68. if(imgFile.exists()){
  69.  
  70. Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
  71. imgIcon.setImageBitmap(myBitmap);
  72. }
  73.  
  74.  
  75. if(row_pos.getTitle() == " ")
  76. txtTitle.setText(row_pos.getPhone_number());
  77. else
  78. txtTitle.setText(row_pos.getTitle());
  79.  
  80. txtSubTitle.setText(row_pos.getSub_title());
  81. txtRightTitle.setText(row_pos.getRight_title());
  82.  
  83. return convertView;
  84. }
  85. }
  86.  
  87. public CustomAdapter(Context context, int resourceId,
  88. ArrayList<RowItem> items) {
  89. super(context, resourceId, items);
  90. rowItem =items; // add this line
  91. this.mcontext = context;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement