PVOCursorAdapter.java (2432B)
1 package de.jandankert.hansemerkur.adapter; 2 3 import java.math.BigDecimal; 4 import java.math.RoundingMode; 5 import java.text.DecimalFormat; 6 import java.text.DecimalFormatSymbols; 7 import java.util.Locale; 8 9 import de.jandankert.hansemerkur.PVOList; 10 import de.jandankert.hansemerkur.R; 11 import de.jandankert.hansemerkur.R.id; 12 import de.jandankert.hansemerkur.R.layout; 13 14 import android.content.Context; 15 import android.database.Cursor; 16 import android.view.LayoutInflater; 17 import android.view.View; 18 import android.view.ViewGroup; 19 import android.view.View.OnClickListener; 20 import android.widget.CursorAdapter; 21 import android.widget.TextView; 22 import android.widget.Toast; 23 24 public class PVOCursorAdapter extends CursorAdapter 25 { 26 27 public PVOCursorAdapter(Context context, Cursor c) 28 { 29 super(context, c); 30 } 31 32 @Override 33 public View newView(Context context, Cursor cursor, ViewGroup parent) 34 { 35 LayoutInflater layoutInflater = LayoutInflater.from(context); 36 37 View view = layoutInflater.inflate(R.layout.pvo_entry, parent, false); 38 39 view.setFocusable(false); 40 return view; 41 42 // return layoutInflater.inflate(R.layout.pvo_entry, parent, false); 43 } 44 45 @Override 46 public void bindView(View view, Context context, Cursor cursor) 47 { 48 // view.setOnClickListener( new OnClickListener() 49 // { 50 // 51 // @Override 52 // public void onClick(View v) 53 // { 54 // System.out.println("short clicked"); 55 // Toast.makeText(v.getContext(), 56 // "Item in unknown position short clicked in Adapter", 57 // Toast.LENGTH_LONG).show(); 58 // } 59 // }); 60 //view.setClickable(false); 61 view.setFocusable(false); 62 63 TextView entfernung = (TextView) view.findViewById(R.id.pvo_entfernung); 64 double entfer = Math.sqrt(cursor.getDouble(cursor 65 .getColumnIndexOrThrow("entfernung"))); 66 DecimalFormat df = new DecimalFormat("####0.0 km"); 67 entfernung.setText("Ca. " 68 + df.format(entfer) 69 .toString()); 70 71 TextView name = (TextView) view.findViewById(R.id.pvo_name); 72 name.setText(cursor.getString(cursor.getColumnIndexOrThrow("Vorname")) 73 + " " 74 + cursor.getString(cursor.getColumnIndexOrThrow("Nachname"))); 75 TextView str = (TextView) view.findViewById(R.id.pvo_str); 76 str.setText(cursor.getString(cursor.getColumnIndexOrThrow("Strasse"))); 77 78 TextView ort = (TextView) view.findViewById(R.id.pvo_ort); 79 ort.setText(cursor.getString(cursor.getColumnIndexOrThrow("Plz"))+ " " + cursor.getString(cursor.getColumnIndexOrThrow("Ort"))); 80 } 81 82 }