Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. package com.todrozd.restoran;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.view.LayoutInflater;
  6. import android.view.View;
  7. import android.view.ViewGroup;
  8. import android.widget.ArrayAdapter;
  9. import android.widget.ImageView;
  10. import android.widget.TextView;
  11.  
  12. import androidx.annotation.NonNull;
  13. import androidx.annotation.Nullable;
  14.  
  15. public class CustomListview extends ArrayAdapter<String> {
  16.  
  17. private String[] restoranName;
  18. private String[] description;
  19. private Integer[] imgId;
  20.  
  21. private Activity context;
  22.  
  23. public CustomListview(Activity context, String[] restoranName, String[] description, Integer[] imgId) {
  24. super(context, R.layout.fragment_restoran, restoranName);
  25.  
  26. this.context = context;
  27. this.restoranName = restoranName;
  28. this.description = description;
  29. this.imgId = imgId;
  30. }
  31.  
  32.  
  33. @NonNull
  34. @Override
  35. public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
  36. View r = convertView;
  37. ViewHolder viewHolder = null;
  38. if(r == null){
  39.  
  40. LayoutInflater layoutInflater = context.getLayoutInflater();
  41. r = layoutInflater.inflate(R.layout.fragment_restoran, null, true);
  42. viewHolder = new ViewHolder(r);
  43. r.setTag(viewHolder);
  44.  
  45. } else {
  46. //время 21:00
  47. viewHolder = (ViewHolder) r.getTag();
  48. }
  49. viewHolder.ivw.setImageResource(imgId[position]);
  50. viewHolder.tvw1.setText(restoranName[position]);
  51. viewHolder.tvw2.setText(description[position]);
  52. return r;
  53.  
  54.  
  55.  
  56. }
  57. class ViewHolder {
  58.  
  59. TextView tvw1;
  60. TextView tvw2;
  61. ImageView ivw;
  62.  
  63. ViewHolder(View v){
  64. tvw1 = (TextView) v.findViewById(R.id.tvrestoranName);
  65. tvw2 = (TextView) v.findViewById(R.id.tvdescription);
  66. ivw = (ImageView) v.findViewById(R.id.imageView);
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement