/* * Copyright 2012 Tallinn University Centre for Educational Technology * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package ee.htk.dippler.app.ArrayAdapters; 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.LinearLayout; import android.widget.TextView; import ee.htk.dippler.app.R; import ee.htk.dippler.app.entities.Answer; public class AnswerArrayAdapter extends ArrayAdapter { private int resource; private LayoutInflater layout_inflater; public AnswerArrayAdapter(Context context, int resource, List objects) { super(context, resource, objects); this.resource = resource; this.layout_inflater = LayoutInflater.from(context); } @Override public View getView ( int position, View convertView, ViewGroup parent ) { ViewHolder viewHolder; Answer answer = getItem( position ); if ( convertView == null ) { /* create a new view of my layout and inflate it in the row */ convertView = ( LinearLayout ) layout_inflater.inflate( resource, null ); viewHolder = new ViewHolder(); viewHolder.answer_title = (TextView) convertView.findViewById(R.id.post_title); viewHolder.answer_grade = (TextView) convertView.findViewById(R.id.list_grade); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } /* Take the TextView from layout and set the city's name */ viewHolder.answer_title.setText(answer.getTitle()); viewHolder.answer_grade.setText(answer.getGrade()+"/"+answer.getMaxpoints()); return convertView; } static class ViewHolder { TextView answer_title; TextView answer_grade; } }