Android Open Source - PlayTogether Activity 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;
// w w w  .  ja  va  2  s. com
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 ActivityAdapter extends ArrayAdapter<ParseObject> {

  protected Context mContext;
  protected List<ParseObject> mActivities;
  
  public ActivityAdapter(Context context, List<ParseObject> activities){
    super(context, R.layout.request_item, activities);
    mContext = context;
    mActivities = activities;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    
    if(convertView == null){
      convertView = LayoutInflater.from(mContext).inflate(R.layout.activity_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);
      holder.partnernameLabel = (TextView) convertView.findViewById(R.id.partnerNameLabel);
      convertView.setTag(holder);
    }
    else{
      holder = (ViewHolder) convertView.getTag();
    }
    
    ParseObject activity = mActivities.get(position);
    if(activity.getString(ParseConstants.KEY_SPORT).equals(ParseConstants.KEY_BADMINTON)){
      holder.iconImageView.setImageResource(R.drawable.badminton);
    }
    else if(activity.getString(ParseConstants.KEY_SPORT).equals(ParseConstants.KEY_PINGPONG)){
      holder.iconImageView.setImageResource(R.drawable.pingpong);
    }
    else if(activity.getString(ParseConstants.KEY_SPORT).equals(ParseConstants.KEY_RUNNING)){
      holder.iconImageView.setImageResource(R.drawable.running);
    }
    else{
      holder.iconImageView.setImageResource(R.drawable.tennis);
    }
    
    
//    holder.nameLabel.setText(activity.getString(ParseConstants.KEY_USERNAME));
    holder.levelLabel.setText(activity.getString(ParseConstants.KEY_LEVEL));
    holder.timeLabel.setText(activity.getString(ParseConstants.KEY_TIME));
    
    return convertView;
  }
  
  private static class ViewHolder{
    ImageView iconImageView;
//    TextView nameLabel;
    TextView levelLabel;
    TextView timeLabel;
    TextView partnernameLabel;
  }
  
  public void refill(List<ParseObject> messages){
    mActivities.clear();
    mActivities.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