Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BreakfastFragment extends ListFragment {
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.row_layout, container, false);
- TextView txt = (TextView) v.findViewById(R.id.label);
- Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/typewriter.ttf");
- txt.setTypeface(font);
- return v;
- }
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- ArrayList<Map<String, String>> list = buildData(); // List that contains Arrays of the form String, String
- String[] from = { "name", "purpose" };
- int[] to = { R.id.label, R.id.price };
- SimpleAdapter adapter = new SimpleAdapter(getActivity(), list, R.layout.row_layout, from, to); //A SimpleAdapter(context, data source, layout for each row, from, to)
- 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;
- }
- }
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <ListView
- android:id="@+id/listView1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" >
- </ListView>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- >
- <TextView
- android:id="@+id/label"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:padding="10dp"
- />
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:paddingRight="5sp"
- android:layout_weight="1"
- >
- <TextView android:id="@+id/price"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="end"
- android:textSize="16sp" /> <!-- layout_gravity is what places prices on the right! -->
- </LinearLayout>
- <LinearLayout
- android:layout_width="0dp"
- android:layout_height="0dp"
- android:layout_gravity="center_vertical"
- android:paddingRight="5sp"
- >
- <ListView
- android:id="@android:id/list"
- android:layout_width="0dp"
- android:layout_height="0dp"
- android:layout_gravity="end"
- />
- </LinearLayout>
- </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement