ArViewer  Android Version
Arvos - Augmented reality viewer open source
 All Classes Namespaces Files Functions Variables
ArvosCustomArrayAdapter.java
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013, Peter Graf
3 
4  This file is part of Arvos - AR Viewer Open Source for Android.
5  Arvos is free software.
6 
7  This program is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 
20  For more information on the AR Viewer Open Source or Peter Graf,
21  please see: http://www.mission-base.com/.
22  */
23 
24 package com.mission_base.arviewer_android;
25 
26 import java.util.ArrayList;
27 
28 import android.app.Activity;
29 import android.view.LayoutInflater;
30 import android.view.View;
31 import android.view.ViewGroup;
32 import android.widget.ArrayAdapter;
33 import android.widget.ImageView;
34 import android.widget.TextView;
35 
36 import com.mission_base.arviewer_android.viewer.Augment;
37 
44 public class ArvosCustomArrayAdapter extends ArrayAdapter<Augment>
45 {
46  private final Activity context;
47  private final ArrayList<Augment> augments;
48  private final int imageId;
49 
50  public ArvosCustomArrayAdapter(Activity context, ArrayList<Augment> augments, int imageId)
51  {
52  super(context, R.layout.lvrowlayout, augments);
53  this.context = context;
54  this.augments = augments;
55  this.imageId = imageId;
56  }
57 
58  static class ViewContainer
59  {
60  public ImageView imageView;
61  public TextView txtTitle;
62  public TextView txtLine;
63  public TextView txtDescription;
64  }
65 
66  @Override
67  public View getView(int position, View view, ViewGroup parent)
68  {
69  ViewContainer viewContainer;
70  View rowView = view;
71 
72  // ---print the index of the row to examine---
73  // Log.d("CustomArrayAdapter",String.valueOf(position));
74 
75  // ---if the row is displayed for the first time---
76  if (rowView == null)
77  {
78  // Log.d("CustomArrayAdapter", "New");
79  LayoutInflater inflater = context.getLayoutInflater();
80  rowView = inflater.inflate(R.layout.lvrowlayout, null, true);
81 
82  // ---create a view container object---
83  viewContainer = new ViewContainer();
84 
85  // ---get the references to all the views in the row---
86  viewContainer.txtTitle = (TextView) rowView.findViewById(R.id.txtAugmentName);
87  viewContainer.txtLine = (TextView) rowView.findViewById(R.id.txtLine);
88  viewContainer.txtDescription = (TextView) rowView.findViewById(R.id.txtDescription);
89  viewContainer.imageView = (ImageView) rowView.findViewById(R.id.icon);
90 
91  // ---assign the view container to the rowView---
92  rowView.setTag(viewContainer);
93  }
94  else
95  {
96  // ---view was previously created; can recycle---
97  // Log.d("CustomArrayAdapter", "Recycling");
98  // ---retrieve the previously assigned tag to get
99  // a reference to all the views; bypass the findViewByID() process,
100  // which is computationally expensive---
101  viewContainer = (ViewContainer) rowView.getTag();
102  }
103 
104  // ---customize the content of each row based on position---
105  viewContainer.txtTitle.setText(augments.get(position).mName);
106  viewContainer.txtLine.setText(augments.get(position).mAuthor);
107  viewContainer.txtDescription.setText(augments.get(position).mDescription);
108  viewContainer.imageView.setImageResource(imageId);
109  return rowView;
110  }
111 }