Example usage for android.app ListFragment ListFragment

List of usage examples for android.app ListFragment ListFragment

Introduction

In this page you can find the example usage for android.app ListFragment ListFragment.

Prototype

public ListFragment() 

Source Link

Usage

From source file:com.cloudbees.gasp.activity.TwitterStreamActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getActionBar().setDisplayHomeAsUpEnabled(true);

    // Use simple FrameLayout for ListFragment
    setContentView(R.layout.gasp_frame_layout);

    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ListFragment list = new ListFragment();
    ft.add(R.id.fragment_content, list);

    // Use a simple TextView layout for ArrayAdapter constructor
    mAdapter = new ArrayAdapter<String>(this, R.layout.gasp_generic_textview);

    // Map ArrayAdapter to ListFragment
    list.setListAdapter(mAdapter);/*  w w w  . ja va2  s .  c om*/

    // RESTResponderFragments call setRetainedInstance(true) in onCreate()
    TwitterResponderFragment responder = (TwitterResponderFragment) fm
            .findFragmentByTag(getString(R.string.twitter_responder));
    if (responder == null) {
        responder = new TwitterResponderFragment();

        ft.add(responder, getString(R.string.twitter_responder));
    }

    ft.commit();
}

From source file:com.cloudbees.gasp.activity.GaspRESTLoaderActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set main content view for Gasp! Reviews
    setContentView(R.layout.gasp_review_activity);

    // Use the Fragments API to display review data
    FragmentManager fm = getFragmentManager();
    ListFragment list = (ListFragment) fm.findFragmentById(R.id.gasp_review_content);
    if (list == null) {
        list = new ListFragment();
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.gasp_review_content, list);
        ft.commit();//from  w  w w  . ja  v a  2 s  .  c  om
    }

    // Array adapter provides access to the review list data
    mAdapter = new ArrayAdapter<String>(this, R.layout.gasp_review_list);
    list.setListAdapter(mAdapter);

    // Load shared preferences from res/xml/preferences.xml (first time only)
    // Subsequent activations will use the saved shared preferences from the device
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    SharedPreferences gaspSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    Log.i(TAG, "Using Gasp Server URI: " + gaspSharedPreferences.getString("gasp_endpoint_uri", ""));
    Uri gaspReviewsUri = Uri.parse(gaspSharedPreferences.getString("gasp_endpoint_uri", ""));

    // Loader arguments: LoaderManager will maintain the state of our Loaders
    // and reload if necessary. 
    Bundle args = new Bundle();
    Bundle params = new Bundle();
    args.putParcelable(ARGS_URI, gaspReviewsUri);
    args.putParcelable(ARGS_PARAMS, params);

    // Initialize the Loader.
    getLoaderManager().initLoader(LOADER_GASP_REVIEWS, args, this);

    // Use gasp-mongo REST service
    new ReviewsRequest().execute();

    try {
        LocationsRequest locations = new LocationsRequest(
                new SpatialQuery(new Location(-122.1139858, 37.3774655), 0.005));

        List<GeoLocation> locationList = locations.execute().get();
        for (GeoLocation geoLocation : locationList) {
            Log.i(TAG, geoLocation.getName());
            Log.i(TAG, " " + geoLocation.getFormattedAddress());
            Log.i(TAG, " " + String.valueOf(geoLocation.getLocation().getLng()));
            Log.i(TAG, " " + String.valueOf(geoLocation.getLocation().getLat()));
        }
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage());
    }
}