Code example for ListFragment

Methods: getActivity, onResume, setListAdapter

0
	private static final SimpleDateFormat FMT = new SimpleDateFormat("dd/MM");
	private static final SimpleDateFormat FMTF = new SimpleDateFormat("dd/MM HH:mm:ss");
 
	@Override 
	public void onResume() { 
		super.onResume(); 
		update(); 
	} 
 
	@Override 
	public void onListItemClick(ListView l, View v, int position, long id) {
		number = getListAdapter().getItemId(position);
		selectedListener.onListItemSelected(number);
	} 
 
	public interface ListItemSelectedListener { 
		public void onListItemSelected(long number);
	} 
 
	@Override 
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putLong("number", number);
	} 
 
	@Override 
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		try { 
			selectedListener = (ListItemSelectedListener) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString() + " must implement ListItemSelectedListener in Activity");
		} 
	} 
 
	@Override 
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		cd = new CardsDAO( getActivity().getApplicationContext() );
 
		update(); 
	} 
 
	private void update() 
	{ 
		setListAdapter(new MyBaseAdapter(getActivity().getApplicationContext(),cd.getAll()));
	} 
 
	private static class MyBaseAdapter extends BaseAdapter {
		private List<Card> listCards;
		private Locale locale = new Locale("pt", "BR");