Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ginger Ranslam
8,156 PointsNeed help with code challenge:displaying checkmarks in a gridview.
Challenge task 1 of 3 Just like our Friends GridView in Ribbit, we want a GridView that displays a custom overlay for an image. In this case it's an overlay to indicate if a player is available offline. If a player is offline, then the overlay image will show to make their avatar fade out a bit. In the getView() method below, start by simply setting the mGridView variable to the parent parameter. Don't forget to cast it!
After doing this challenge it tells me "Bummer! Looks like you haven't set mGridView yet!" I need some guidance on what I'm doing wrong if anyone can help.
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import com.parse.ParseUser;
public class PlayerAdapter extends ArrayAdapter<ParseUser> {
public GridView mGridView;
/*
* Some code has been omitted for brevity!
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.player_item, null);
holder = new ViewHolder();
holder.playerImageView = (ImageView)convertView.findViewById(R.id.playerImageView);
holder.overlayImageView = (ImageView)convertView.findViewById(R.id.overlayImageView);
convertView.setTag(holder);
}
else {
holder = (ViewHolder)convertView.getTag();
}
//Here is the code I added
GridView mGridView = (GridView) parent;
return convertView;
}
private static class ViewHolder {
ImageView playerImageView;
ImageView overlayImageView;
}
}
Marko Koron
20,658 PointsMarko Koron
20,658 PointsJust use:
mGridView = (GridView) parent;mGridView is already declared as a member class variable up in the code.