Android Open Source - PlayTogether Request Adapter






From Project

Back to project page PlayTogether.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project PlayTogether listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.rockylearnstodevelop.playtogether;
//from   w  w w  .  ja v  a 2  s.  co  m
import java.util.List;

import android.content.Context;
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 com.parse.ParseObject;

public class RequestAdapter extends ArrayAdapter<ParseObject> {

  protected Context mContext;
  protected List<ParseObject> mRequests;
  
  public RequestAdapter(Context context, List<ParseObject> requests){
    super(context, R.layout.request_item, requests);
    mContext = context;
    mRequests = requests;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    
    if(convertView == null){
      convertView = LayoutInflater.from(mContext).inflate(R.layout.request_item, null);
      holder = new ViewHolder();
      holder.iconImageView = (ImageView) convertView.findViewById(R.id.requestIcon);
      holder.nameLabel = (TextView) convertView.findViewById(R.id.senderLabel);
      holder.levelLabel = (TextView) convertView.findViewById(R.id.levelLabel);
      holder.timeLabel = (TextView) convertView.findViewById(R.id.timeLabel);
      convertView.setTag(holder);
    }
    else{
      holder = (ViewHolder) convertView.getTag();
    }
    
    ParseObject request = mRequests.get(position);
    if(request.getString(ParseConstants.KEY_SPORT).equals(ParseConstants.KEY_BADMINTON)){
      holder.iconImageView.setImageResource(R.drawable.badminton);
    }
    else if(request.getString(ParseConstants.KEY_SPORT).equals(ParseConstants.KEY_PINGPONG)){
      holder.iconImageView.setImageResource(R.drawable.pingpong);
    }
    else if(request.getString(ParseConstants.KEY_SPORT).equals(ParseConstants.KEY_RUNNING)){
      holder.iconImageView.setImageResource(R.drawable.running);
    }
    else{
      holder.iconImageView.setImageResource(R.drawable.tennis);
    }
    
    
    holder.nameLabel.setText(request.getString(ParseConstants.KEY_SENDERNAME));
    holder.levelLabel.setText(request.getString(ParseConstants.KEY_LEVEL));
    holder.timeLabel.setText(request.getString(ParseConstants.KEY_TIME));
    
    return convertView;
  }
  
  private static class ViewHolder{
    ImageView iconImageView;
    TextView nameLabel;
    TextView levelLabel;
    TextView timeLabel;
  }
  
  public void refill(List<ParseObject> messages){
    mRequests.clear();
    mRequests.addAll(messages);
    notifyDataSetChanged();
  }
}




Java Source Code List

com.rockylearnstodevelop.playtogether.ActivitiesFragment.java
com.rockylearnstodevelop.playtogether.ActivityAdapter.java
com.rockylearnstodevelop.playtogether.FileHelper.java
com.rockylearnstodevelop.playtogether.ImageResizer.java
com.rockylearnstodevelop.playtogether.LoginActivity.java
com.rockylearnstodevelop.playtogether.MainActivity.java
com.rockylearnstodevelop.playtogether.MatchActivity.java
com.rockylearnstodevelop.playtogether.NoMatchActivity.java
com.rockylearnstodevelop.playtogether.ParseConstants.java
com.rockylearnstodevelop.playtogether.PlayWithMe2Application.java
com.rockylearnstodevelop.playtogether.RequestAdapter.java
com.rockylearnstodevelop.playtogether.RequestFragment.java
com.rockylearnstodevelop.playtogether.SectionsPagerAdapter.java
com.rockylearnstodevelop.playtogether.SignupActivity.java
com.rockylearnstodevelop.playtogether.UserInfoActivity.java
com.rockylearnstodevelop.playtogether.WannaPlayFragment.java