Example usage for android.widget ListView setAdapter

List of usage examples for android.widget ListView setAdapter

Introduction

In this page you can find the example usage for android.widget ListView setAdapter.

Prototype

@Override
public void setAdapter(ListAdapter adapter) 

Source Link

Document

Sets the data behind this ListView.

Usage

From source file:com.example.android.uamp.ui.MediaBrowserFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LogHelper.d(TAG, "fragment.onCreateView");
    View rootView = inflater.inflate(R.layout.fragment_list, container, false);

    mErrorView = rootView.findViewById(R.id.playback_error);
    mErrorMessage = (TextView) mErrorView.findViewById(R.id.error_message);

    mBrowserAdapter = new BrowseAdapter(getActivity());

    ListView listView = (ListView) rootView.findViewById(R.id.list_view);
    listView.setAdapter(mBrowserAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from www  .j  a  v  a  2s  . c o  m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            checkForUserVisibleErrors(false);
            MediaBrowserCompat.MediaItem item = mBrowserAdapter.getItem(position);
            mMediaFragmentListener.onMediaItemSelected(item);
        }
    });

    return rootView;
}

From source file:cat.terrones.devops.radiofx.ui.MediaBrowserFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(TAG, "fragment.onCreateView");
    View rootView = inflater.inflate(R.layout.fragment_list, container, false);

    mErrorView = rootView.findViewById(R.id.playback_error);
    mErrorMessage = (TextView) mErrorView.findViewById(R.id.error_message);

    mBrowserAdapter = new BrowseAdapter(getActivity());

    ListView listView = (ListView) rootView.findViewById(R.id.list_view);
    listView.setAdapter(mBrowserAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from  w  ww  .  j a va 2s. com*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            checkForUserVisibleErrors(false);
            MediaBrowserCompat.MediaItem item = mBrowserAdapter.getItem(position);
            mMediaFragmentListener.onMediaItemSelected(item);
        }
    });

    return rootView;
}

From source file:com.brkc.traffic.ui.image.ImageListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View v = inflater.inflate(R.layout.image_list_fragment, container, false);
    final ListView mListView = (ListView) v.findViewById(R.id.listView);
    mListView.setAdapter(mAdapter);
    mListView.setOnItemClickListener(this);
    mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override/*from  w  w  w.ja v  a2 s.  c  o m*/
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            // Pause fetcher to ensure smoother scrolling when flinging
            if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
                // Before Honeycomb pause image loading on scroll to help with performance
                if (!Utils.hasHoneycomb()) {
                    mImageFetcher.setPauseWork(true);
                }
            } else {
                mImageFetcher.setPauseWork(false);
            }
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
        }
    });

    return v;
}

From source file:com.example.lidorcg.sunshine.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final List<String> weekForecast = new ArrayList<>();

    // Now that we have some dummy forecast data, create an ArrayAdapter.
    // The ArrayAdapter will take data from a source (like our dummy forecast) and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ArrayAdapter<>(getActivity(), // The current context (this activity)
            R.layout.list_item_forecast, // The name of the layout ID.
            R.id.list_item_forecast_textview, // The ID of the textview to populate.
            weekForecast);//from   ww w . j av  a 2 s.c om

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                    weekForecast.get(position));
            startActivity(intent);
        }
    });

    return rootView;
}

From source file:am.roadpolice.roadpolice.ViolationInfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_violation_info);

    DialogRateUs.showRateUs(getApplicationContext(), getSupportFragmentManager());

    // Customize Action Bar
    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(0xFF1A237E));
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(Html.fromHtml("<small>" + getString(R.string.title_activity_info) + "</small>"));

    final Intent intent = getIntent();
    // Get Data which is sent from MainActivity.
    mAutoLogin = intent.getBooleanExtra(EXTRA_AUTO_LOGIN, false);
    ArrayList<ViolationInfo> violationList = intent.getParcelableArrayListExtra(EXTRA_VIOLATION_INFO_LIST);

    ViolationInfoAdapter adapter = new ViolationInfoAdapter(getApplicationContext(), violationList);

    ListView listView = (ListView) findViewById(R.id.listViewViolationInfo);
    listView.setOnItemClickListener(this);
    listView.setEmptyView(findViewById(R.id.textViewEmpty));
    listView.setAdapter(adapter);
}

From source file:com.autoparts.buyers.action_content.ExamplesActivity.java

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

    //        mSettingsChangedListener = new SettingsChangedListener();

    setContentView(R.layout.example);//from   w w  w .  j a  v  a2 s  . c o  m

    viewActionsContentView = (ActionsContentView) findViewById(R.id.actionsContentView);
    viewActionsContentView.setSwipingType(ActionsContentView.SWIPING_EDGE);
    viewActionsContentView.showActions();
    viewActionsContentView.setSpacingWidth(0);
    viewActionsContentView.setShadowVisible(false);
    viewActionsContentView.setFadeValue(0);
    //        viewActionsContentView.setSwipingType(ActionsContentView.SWIPING_ALL);
    viewActionsContentView.setSwipingType(ActionsContentView.SWIPING_EDGE);
    int value = 100;
    final float mDensity = getResources().getDisplayMetrics().density;

    viewActionsContentView.setActionsSpacingWidth((int) (value * mDensity));

    final ListView viewActionsList = (ListView) findViewById(R.id.actions);
    final ActionsAdapter actionsAdapter = new ActionsAdapter(this);
    viewActionsList.setAdapter(actionsAdapter);
    viewActionsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapter, View v, int position, long flags) {
            final Uri uri = actionsAdapter.getItem(position);
            Log.d("actions", "uri==" + uri);
            //                Log.d("actions", "EffectsExampleActivity.URI==" + EffectsExampleActivity.URI);
            //
            //                if (EffectsExampleActivity.URI.equals(uri)) {
            //                    startActivity(new Intent(getBaseContext(), EffectsExampleActivity.class));
            //                    return;
            //                }

            updateContent(uri);
            viewActionsContentView.showContent();
        }
    });

    if (savedInstanceState != null) {
        currentUri = Uri.parse(savedInstanceState.getString(STATE_URI));
        currentContentFragmentTag = savedInstanceState.getString(STATE_FRAGMENT_TAG);
    }

    updateContent(currentUri);
}

From source file:com.example.android.sunshine.app.ForcastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Create some dummy data for the ListView.  Here's a sample weekly forecast
    String[] data = { "Mon 6/23- Sunny - 31/17", "Tue 6/24 - Foggy - 21/8", "Wed 6/25 - Cloudy - 22/17",
            "Thurs 6/26 - Rainy - 18/11", "Fri 6/27 - Foggy - 21/10",
            "Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18", "Sun 6/29 - Sunny - 20/7" };
    List<String> weekForecast = new ArrayList<String>(Arrays.asList(data));

    // Now that we have some dummy forecast data, create an ArrayAdapter.
    // The ArrayAdapter will take data from a source (like our dummy forecast) and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ArrayAdapter<String>(getActivity(), // The current context (this activity)
            R.layout.list_item_forcast, // The name of the layout ID.
            R.id.list_item_forcast_textview, // The ID of the textview to populate.
            weekForecast);//from   w  ww  .j  av a2s . c  o  m

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.list_view_forcast);
    listView.setAdapter(mForecastAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Toast.makeText(getActivity(), mForecastAdapter.getItem(i), Toast.LENGTH_SHORT).show();
        }
    });

    return rootView;
}

From source file:com.cerema.cloud2.ui.fragment.SearchShareesFragment.java

private void updateListOfUserGroups() {
    // Update list of users/groups
    // TODO Refactoring: create a new {@link ShareUserListAdapter} instance with every call should not be needed
    mUserGroupsAdapter = new ShareUserListAdapter(getActivity().getApplicationContext(),
            R.layout.share_user_item, mShares, this);

    // Show data//from w  w  w.j  a v a 2s . com
    ListView usersList = (ListView) getView().findViewById(R.id.searchUsersListView);

    if (mShares.size() > 0) {
        usersList.setVisibility(View.VISIBLE);
        usersList.setAdapter(mUserGroupsAdapter);

    } else {
        usersList.setVisibility(View.GONE);
    }
}

From source file:com.example.android.pets.CatalogActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_catalog);

    // Setup FAB to open EditorActivity
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override//from  w  w  w .  j  av  a2s. c o  m
        public void onClick(View view) {
            Intent intent = new Intent(CatalogActivity.this, EditorActivity.class);
            startActivity(intent);
        }
    });

    ListView displayView = (ListView) findViewById(R.id.list);
    /*View emptyView =findViewById(R.id.Empty_view);
     displayView.setEmptyView(emptyView);*/

    mCursorAdapter = new PetsCursorAdapter(this, null);
    displayView.setAdapter(mCursorAdapter);

    displayView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {

            Intent intent = new Intent(CatalogActivity.this, EditorActivity.class);

            Uri currentPetUri = ContentUris.withAppendedId(PetsEntry.CONTENT_URI, id);

            intent.setData(currentPetUri);

            startActivity(intent);

        }
    });

    //kick off the Loader
    getLoaderManager().initLoader(PET_LOADER, null, this);

}

From source file:com.example.android.sunshine.sunshine.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Create some dummy data for the ListView.  Here's a sample weekly forecast
    String[] data = { "Mon 6/23- Sunny - 31/17", "Tue 6/24 - Foggy - 21/8", "Wed 6/25 - Cloudy - 22/17",
            "Thurs 6/26 - Rainy - 18/11", "Fri 6/27 - Foggy - 21/10",
            "Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18", "Sun 6/29 - Sunny - 20/7" };
    List<String> weekForecast = new ArrayList<>(Arrays.asList(data));

    // Now that we have some dummy forecast data, create an ArrayAdapter.
    // The ArrayAdapter will take data from a source (like our dummy forecast) and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ArrayAdapter<>(getActivity(), // The current context (this activity)
            R.layout.list_item_forecast, // The name of the layout ID.
            R.id.list_item_forecast_textview, // The ID of the textview to populate.
            weekForecast);/*from w w  w. j av  a  2s.  co m*/

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);

    return rootView;
}