Skip to content

Instantly share code, notes, and snippets.

@yucc136
yucc136 / ContractFragment.java
Created December 13, 2012 13:22 — forked from JakeWharton/ContractFragment.java
Base fragment to ensure the parent activity implements a contract interface.
/* Base fragment to ensure the parent activity implements a contract interface. */
public abstract class ContractFragment<T> extends Fragment {
private T mContract;
@Override
public void onAttach(Activity activity) {
try {
mContract = (T)activity;
} catch (ClassCastException e) {
throw new IllegalStateException(activity.getClass().getSimpleName()
@yucc136
yucc136 / ViewHoldingAdapter.java
Created December 13, 2012 13:19 — forked from johnkil/ViewHoldingAdapter.java
Template for a list adapter which uses a view holder to cache lookups.
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder vh = ViewHolder.get(convertView, parent);
Item item = getItem(position);
vh.title.setText(item.title);
vh.subtitle.setText(item.subtitle);
return vh.root;
}