|
@@ -0,0 +1,74 @@
|
|
|
+package de.tudarmstadt.informatik.hostage.ui2.adapter;
|
|
|
+
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.content.Context;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.SimpleAdapter;
|
|
|
+import android.widget.TextView;
|
|
|
+import de.tudarmstadt.informatik.hostage.R;
|
|
|
+
|
|
|
+public class RecordListAdapter extends SimpleAdapter {
|
|
|
+ private final Context context;
|
|
|
+ private final ArrayList<HashMap<String, String>> values;
|
|
|
+ private String[] from;
|
|
|
+ private int[] to;
|
|
|
+
|
|
|
+ public RecordListAdapter(Context context, ArrayList<HashMap<String, String>> objects, int resource, String[] from,
|
|
|
+ int[] to) {
|
|
|
+ super(context, objects, resource, from, to);
|
|
|
+ this.context = context;
|
|
|
+ this.values = objects;
|
|
|
+ this.from = from;
|
|
|
+ this.to = to;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
+ LayoutInflater inflater = (LayoutInflater) context
|
|
|
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
+ View rowView = inflater.inflate(R.layout.record_list_item, parent, false);
|
|
|
+
|
|
|
+
|
|
|
+ HashMap<String, String> object = this.values.get(position);
|
|
|
+
|
|
|
+ for(int i = 0; i < this.from.length; i++){
|
|
|
+ String key = this.from[i];
|
|
|
+ String text = object.get(key);
|
|
|
+ int id = this.to[i];
|
|
|
+ TextView tView = (TextView) rowView.findViewById(id);
|
|
|
+ tView.setText(text);
|
|
|
+ }
|
|
|
+
|
|
|
+ return rowView;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /*****************************
|
|
|
+ *
|
|
|
+ * Date Transform
|
|
|
+ *
|
|
|
+ * ***************************/
|
|
|
+
|
|
|
+
|
|
|
+ @SuppressLint("SimpleDateFormat")
|
|
|
+ private String getDateAsString(long timeStamp) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
+ Date netDate = (new Date(timeStamp));
|
|
|
+ return sdf.format(netDate);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return "xx";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|