/* * 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.Comment; public class CommentArrayAdapter extends ArrayAdapter { private int resource; private LayoutInflater layout_inflater; public CommentArrayAdapter(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; Comment post = 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.post_title = (TextView) convertView.findViewById(R.id.post_title); viewHolder.post_content = (TextView) convertView.findViewById(R.id.post_content); viewHolder.posted_on = (TextView) convertView.findViewById(R.id.post_posted_on); convertView.findViewById(R.id.right_arrow).setVisibility(View.GONE); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } /* Take the TextView from layout and set the city's name */ viewHolder.post_title.setText(post.getPostTitle()); viewHolder.post_content.setVisibility(View.GONE); viewHolder.posted_on.setText(post.getCreatedDate()); return convertView; } static class ViewHolder { TextView post_title; TextView post_content; TextView posted_on; } }