Dacsi

Untitled

Jul 12th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. package com.andsp.aaaaaa;
  2.  
  3. import android.app.Activity;
  4. import android.util.Log;
  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 java.util.ArrayList;
  13.  
  14. /*
  15. * {@link AndroidFlavorAdapter} is an {@link ArrayAdapter} that can provide the layout for each list
  16. * based on a data source, which is a list of {@link AndroidFlavor} objects.
  17. * */
  18. public class GridItemAdapter extends ArrayAdapter<GridItem> {
  19.  
  20. private static final String LOG_TAG = GridItemAdapter.class.getSimpleName();
  21.  
  22.  
  23. public GridItemAdapter(Activity context, ArrayList<GridItem> gridItems) {
  24. // Here, we initialize the ArrayAdapter's internal storage for the context and the list.
  25. // the second argument is used when the ArrayAdapter is populating a single TextView.
  26. // Because this is a custom adapter for two TextViews and an ImageView, the adapter is not
  27. // going to use this second argument, so it can be any value. Here, we used 0.
  28. super(context, 0, gridItems);
  29. }
  30.  
  31. @Override
  32. public View getView(int position, View convertView, ViewGroup parent) {
  33. // Check if the existing view is being reused, otherwise inflate the view
  34. View gridItemView = convertView;
  35. if(gridItemView == null) {
  36. gridItemView = LayoutInflater.from(getContext()).inflate(
  37. R.layout.grid_item, parent, false);
  38. }
  39.  
  40. // Get the object located at this position in the list
  41. GridItem currentGridItem = getItem(position);
  42.  
  43. // Find the TextView in the grid_item.xml layout
  44. TextView nameTextView = (TextView) gridItemView.findViewById(R.id.text_1);
  45. // set this text on the name TextView
  46. nameTextView.setText(currentGridItem.getSoundName());
  47.  
  48.  
  49.  
  50. if(currentGridItem.isPlaying) {
  51. Log.v("GridItemAdapter", "value of isPlaying is = \"" + "\"");
  52. //set the icon to pause one
  53. ImageView playIcon = (ImageView) gridItemView.findViewById(R.id.image_1);
  54. playIcon.setImageResource(R.drawable.pause_ic);
  55.  
  56. } else {
  57. Log.v("GridItemAdapter", "value of isPlaying is = \"" + "\"");
  58. //set the icon to playing one
  59. ImageView playIcon = (ImageView) gridItemView.findViewById(R.id.image_1);
  60. playIcon.setImageResource(R.drawable.play_ic);
  61. }
  62.  
  63.  
  64.  
  65. // Return the whole list item layout (containing 2 TextViews and an ImageView)
  66. // so that it can be shown in the ListView
  67. return gridItemView;
  68. }
  69.  
  70.  
  71. }
Add Comment
Please, Sign In to add comment