1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| public class MoviesFragment extends ListFragment {
MyArrayAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayList<Map<String, String>> list = buildData();
MyArrayAdapter adapter = new MyArrayAdapter(getActivity(), list);
setListAdapter(adapter);
}
private ArrayList<Map<String, String>> buildData() {
ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
list.add(putData("Greek Yoghourt & Fruit","£2.25"));
list.add(putData("Fruit Cobbler", "£2.25"));
list.add(putData("Honey Roasted Fruit & Yoghurt", "£2.25")); //PutData is defined below
list.add(putData("Fruit Fool", "£2.25"));
list.add(putData("Bircher", "£2.25"));
list.add(putData("Porridge","£1.95"));
list.add(putData("Stewed Fruit Topping","£0.50"));
list.add(putData("Candied Pralines","£0.50"));
list.add(putData("House Bacon", "£3.75"));
list.add(putData("Simply Bacon","£3.75"));
list.add(putData("House Mushroom", "£3.50"));
list.add(putData("Peanut Butter & Homemade Jam", "£3.50"));
list.add(putData("Eggs on toast","£4.00"));
list.add(putData("House Eggs","£4.75"));
list.add(putData("Spanish Eggs","£4.75"));
list.add(putData("Smoked Salmon Eggs","£4.75"));
list.add(putData("The Full Breakfast","£5.25"));
list.add(putData("Chorizo Hash", "£5.25"));
return list;
}
private HashMap<String, String> putData(String name, String purpose) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("name", name);
item.put("purpose", purpose);
return item;
}
public class MyArrayAdapter extends ArrayAdapter<HashMap<String, String>> {
public MyArrayAdapter(Context context, ArrayList<Map<String,String>> list) {
super(context, R.layout.row_layouts, R.id.label);
}
public MyArrayAdapter(Context context, HashMap<String, String>[] items) {
super(context, R.layout.row_layouts, R.id.label, items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView1 = (TextView) view.findViewById(R.id.label);
textView1.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/typewriter.ttf"));
TextView textView2 = (TextView) view.findViewById(R.id.price);
textView2.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/typewriter.ttf"));
return view;
}
}
} |
Partager