Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.andsp.aaaaaa;
- import android.app.Activity;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- import java.util.ArrayList;
- /*
- * {@link AndroidFlavorAdapter} is an {@link ArrayAdapter} that can provide the layout for each list
- * based on a data source, which is a list of {@link AndroidFlavor} objects.
- * */
- public class GridItemAdapter extends ArrayAdapter<GridItem> {
- private static final String LOG_TAG = GridItemAdapter.class.getSimpleName();
- public GridItemAdapter(Activity context, ArrayList<GridItem> gridItems) {
- // Here, we initialize the ArrayAdapter's internal storage for the context and the list.
- // the second argument is used when the ArrayAdapter is populating a single TextView.
- // Because this is a custom adapter for two TextViews and an ImageView, the adapter is not
- // going to use this second argument, so it can be any value. Here, we used 0.
- super(context, 0, gridItems);
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- // Check if the existing view is being reused, otherwise inflate the view
- View gridItemView = convertView;
- if(gridItemView == null) {
- gridItemView = LayoutInflater.from(getContext()).inflate(
- R.layout.grid_item, parent, false);
- }
- // Get the object located at this position in the list
- GridItem currentGridItem = getItem(position);
- // Find the TextView in the grid_item.xml layout
- TextView nameTextView = (TextView) gridItemView.findViewById(R.id.text_1);
- // set this text on the name TextView
- nameTextView.setText(currentGridItem.getSoundName());
- if(currentGridItem.isPlaying) {
- Log.v("GridItemAdapter", "value of isPlaying is = \"" + "\"");
- //set the icon to pause one
- ImageView playIcon = (ImageView) gridItemView.findViewById(R.id.image_1);
- playIcon.setImageResource(R.drawable.pause_ic);
- } else {
- Log.v("GridItemAdapter", "value of isPlaying is = \"" + "\"");
- //set the icon to playing one
- ImageView playIcon = (ImageView) gridItemView.findViewById(R.id.image_1);
- playIcon.setImageResource(R.drawable.play_ic);
- }
- // Return the whole list item layout (containing 2 TextViews and an ImageView)
- // so that it can be shown in the ListView
- return gridItemView;
- }
- }
Add Comment
Please, Sign In to add comment