Guest User

Untitled

a guest
Jun 22nd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. public class Best_Product extends BaseAdapter {
  2. View gridView;
  3. private Context context;
  4.  
  5. private ArrayList<HashMap<String, String>> MyArr = new ArrayList<HashMap<String, String>>();
  6. Function_List fun_lib = new Function_List();
  7. public Best_Product(Context c,ArrayList<HashMap<String, String>> json_value) {
  8. // TODO Auto-generated method stub
  9. context = c;
  10. MyArr = json_value;
  11. }
  12.  
  13. public int getCount() {
  14. // TODO Auto-generated method stub
  15. int total_size = MyArr.size();
  16. Log.d("size of item", "" + MyArr.size());
  17. if((MyArr.size()%2)==0)
  18. {
  19. // do nothing
  20. }
  21. else
  22. {
  23. total_size = MyArr.size()+1;
  24. }
  25.  
  26. return total_size;
  27. }
  28.  
  29. public Object getItem(int position) {
  30. // TODO Auto-generated method stub
  31. return position;
  32. }
  33.  
  34. public long getItemId(int position) {
  35. // TODO Auto-generated method stub
  36. HashMap<String, String> mapAtPostion = MyArr.get(position);
  37. return Long.valueOf(MyArr.get(position).get("product_id"));
  38.  
  39. }
  40.  
  41. public View getView(int position, View convertView, ViewGroup parent) {
  42.  
  43. View view = convertView;
  44. RelativeLayout background_color; // this will be the Relativelayout of the content of GridView. you will be set backgroud color of last item
  45. LayoutInflater inflater = (LayoutInflater) context
  46. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  47. if (view == null) {
  48. view = new View(context);
  49. view = inflater.inflate(R.layout.home_best_collection_content, parent, false);
  50. background_color = (RelativeLayout)view.findViewById(R.id.bckground);
  51. //checking last item of the array
  52. if(position ==MyArr.size()-1)
  53. {
  54. //change the last item background color
  55. background_color.setBackgroundColor();
  56. }
  57. else
  58. {
  59. // do the work here
  60. }
  61. }
  62. else
  63. {
  64.  
  65. }
  66. return view;
  67. }
  68. }
Add Comment
Please, Sign In to add comment