Code example for ListFragment

Methods: getActivity, onStart, setListAdapter

0
        updateListView(); 
    } 
 
    @Override 
    public void onStart() { 
        super.onStart(); 
        Log.v(TAG, "On start");
        updateListView(); 
    } 
 
    @Override 
    public void onAttach(Activity activity) {
        super.onAttach(activity);
 
        // This makes sure that the container activity has implemented 
        // the callback interface. If not, it throws an exception. 
        try { 
            mCallback = (OnHeadlineSelectedListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnHeadlineSelectedListener"); 
        } 
    } 
 
    @Override 
    public void onListItemClick(ListView l, View v, int position, long id) {
        // Notify the parent activity of selected item 
    	String string = cardNames.get(position);
    	Log.v(TAG, "onListItemClick Card name: " + string);
        SimpleDateFormat dateFormat = new SimpleDateFormat(Card.DATE_FORMAT); 
        try { 
        	Date convertedDate = dateFormat.parse(string);
        	mCallback.onCardSelected(convertedDate);
        } catch (ParseException pe) {
        	Log.e(TAG, pe.getMessage());
        } 
         
        // Set the item as checked to be highlighted when in two-pane layout 
        getListView().setItemChecked(position, true);
    } 
     
    public List<String> getCardNames() {
		return cardNames;
	} 
 
	public void setCardNames(List<String> cardNames) {
		this.cardNames = cardNames;
	} 
	 
	public void resetCardNames() { 
		this.cardNames = new ArrayList<String>();
		updateListView(); 
	}     
     
    public void updateListView() { 
        int layout = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
                android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_1;
        // Create an array adapter for the list view 
        Log.v(TAG, cardNames.toString());
        setListAdapter(new ArrayAdapter<String>(getActivity(), layout, cardNames));
    } 
     
}