Back to project page game_guess_lib.
The source code is released under:
MIT License
If you think the Android project game_guess_lib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.wkmf.guess.lib.screen.adapter; /*from ww w . j a va2 s. c o m*/ import android.content.Context; import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import com.wkmf.guess.lib.R; import com.wkmf.guess.lib.structure.GuessConfig; import com.wkmf.guess.lib.structure.GuessQuestion; import java.util.List; /** * Created by ernestofndz on 22/02/14. */ public class QuestionsAdapter extends BaseAdapter { private GuessConfig config; private Context context; private List<GuessQuestion> questions; private LayoutInflater inflater; // constructor public QuestionsAdapter(Context context, List<GuessQuestion> questions, GuessConfig config) { this.context = context; this.questions = questions; this.config = config; } @Override public int getCount() { return this.questions.size(); } @Override public Object getItem(int i) { return this.questions.get(i); } @Override public long getItemId(int i) { return 0; } @Override public View getView(int i, View view, ViewGroup viewGroup) { // asignamos el layout que deseamos this.inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v; if (view == null) v = this.inflater.inflate(R.layout.item_question, viewGroup, false); else v = view; // recuperamos el elemento final GuessQuestion question = (GuessQuestion) getItem(i); if (question != null) { // inicializamos los datos final TextView questionNumber = (TextView) v.findViewById(R.id.question_number); questionNumber.setText(String.valueOf(i + 1)); // damos color de fondo if(question.isCompleted()){ // nivel completado v.findViewById(R.id.question_root).setBackgroundColor(Color.parseColor(this.config.getTagDoneBackgroundColor())); questionNumber.setTextColor(Color.parseColor(this.config.getTagDoneTextColor())); }else{ // no completado v.findViewById(R.id.question_root).setBackgroundColor(Color.parseColor(this.config.getTagBackgroundColor())); questionNumber.setTextColor(Color.parseColor(this.config.getTagTextColor())); } // lo aadimos al tag v.setTag(question); } // devolvemos la vista return v; } }