2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.example.android.supportv4.app;
19 import com.example.android.supportv4.Shakespeare;
21 import android.support.v4.app.FragmentActivity;
22 import android.support.v4.app.ListFragment;
24 import android.os.Bundle;
25 import android.util.Log;
26 import android.view.View;
27 import android.widget.ArrayAdapter;
28 import android.widget.ListView;
31 * Demonstration of using ListFragment to show a list of items
32 * from a canned array.
34 public class FragmentListArraySupport extends FragmentActivity {
37 protected void onCreate(Bundle savedInstanceState) {
38 super.onCreate(savedInstanceState);
40 // Create the list fragment and add it as our sole content.
41 if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
42 ArrayListFragment list = new ArrayListFragment();
43 getSupportFragmentManager().beginTransaction().add(android.R.id.content, list).commit();
47 public static class ArrayListFragment extends ListFragment {
50 public void onActivityCreated(Bundle savedInstanceState) {
51 super.onActivityCreated(savedInstanceState);
52 setListAdapter(new ArrayAdapter<String>(getActivity(),
53 android.R.layout.simple_list_item_1, Shakespeare.TITLES));
57 public void onListItemClick(ListView l, View v, int position, long id) {
58 Log.i("FragmentList", "Item clicked: " + id);