Android Open Source - Android-FactsGame Scores Adapter






From Project

Back to project page Android-FactsGame.

License

The source code is released under:

Apache License

If you think the Android project Android-FactsGame 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 ie.iamshanedoyle.factsgame.adapters;
/* w  w  w. j a va2  s.  c o  m*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import ie.iamshanedoyle.factsgame.R;
import ie.iamshanedoyle.factsgame.models.Score;

/**
 * The ScoresAdapter is used to display the scores.
 */
public class ScoresAdapter extends ArrayAdapter<Score> {

    static class ViewHolder {
        public TextView textViewUser;
        public TextView textViewScore;
        public TextView textViewPosition;
    }

    private List<Score> mScores;
    private final String[] mPositions;

    public ScoresAdapter(Context context, List<Score> scores) {
        super(context, R.layout.list_item_scores);
        mScores = scores;
        mPositions = getContext().getResources().getStringArray(R.array.positions);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public Score getItem(int position) {
        return mScores.get(position);
    }

    @Override
    public int getCount() {
        return mScores.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Score score = getItem(position);

        if (score == null) {
            return null;
        }

        View view = convertView;

        ViewHolder viewHolder;

        if (view == null) {
            LayoutInflater inflater = (LayoutInflater.from(getContext()));
            view = inflater.inflate(R.layout.list_item_scores, parent, false);

            if (view == null) {
                return null;
            }

            viewHolder = new ViewHolder();
            viewHolder.textViewUser = (TextView) view.findViewById(R.id.textViewUser);
            viewHolder.textViewPosition = (TextView) view.findViewById(R.id.textViewPosition);
            viewHolder.textViewScore = (TextView) view.findViewById(R.id.textViewScore);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.textViewUser.setText(score.getUser());
        viewHolder.textViewScore.setText(Integer.toString(score.getValue()));
        viewHolder.textViewPosition.setText(mPositions[position]);

        return view;
    }
}




Java Source Code List

ie.iamshanedoyle.factsgame.Constants.java
ie.iamshanedoyle.factsgame.activities.GameActivity.java
ie.iamshanedoyle.factsgame.activities.HomeActivity.java
ie.iamshanedoyle.factsgame.activities.HowToPlayActivity.java
ie.iamshanedoyle.factsgame.activities.ScoresActivity.java
ie.iamshanedoyle.factsgame.adapters.ScoresAdapter.java
ie.iamshanedoyle.factsgame.models.Question.java
ie.iamshanedoyle.factsgame.models.Score.java
ie.iamshanedoyle.factsgame.views.CountdownTimerView.java
ie.iamshanedoyle.factsgame.views.DividerView.java