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.glabs.homegenie.widgets.MediaServerDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    _view = getActivity().getLayoutInflater().inflate(R.layout.widget_control_mediaserver, null);
    builder.setView(_view);/* w w  w.j a  v  a2  s .co  m*/

    builder.setMessage(_module.getDisplayName())
            .setPositiveButton("Play", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // Play to...
                    playMediaTo();
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User cancelled the dialog
                }
            });

    mAdapter = new MediaFilesAdapter(_view.getContext(), R.layout.widget_control_mediaserver_item,
            new ArrayList<MediaEntry>());
    final ListView lv = (ListView) _view.findViewById(R.id.filesList);
    lv.setAdapter(mAdapter);
    //
    if (navigationStack.size() == 0) {
        navigationStack.add("0");
    }
    //
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            MediaEntry clicked = mAdapter.getItem(i);
            mAdapter.setSelectedIndex(i);
            _selectedMedia = null;
            //
            if (clicked.Class.indexOf("object.container") == 0) {
                // browse to folder
                _dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
                if (clicked.Title.equals(PARENT_FOLDER)) {
                    navigationStack.removeLast();
                } else {
                    navigationStack.add(clicked.Id);
                }
                browseMediaFolder(lv);
            } else {
                // set current media file
                _selectedMedia = clicked;
                _dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
            }
        }
    });
    //

    Control.getGroupModules("", new Control.GetGroupModulesCallback() {
        @Override
        public void groupModulesUpdated(ArrayList<Module> modules) {
            ArrayAdapter<CharSequence> playtoitems = new ArrayAdapter<CharSequence>(_view.getContext(),
                    android.R.layout.simple_spinner_item);
            //
            playtoitems.add("This device");
            //
            for (int m = 0; m < modules.size(); m++) {
                Module module = modules.get(m);
                ModuleParameter devtype = module.getParameter("UPnP.StandardDeviceType");
                if (devtype != null && devtype.Value.equals("MediaRenderer")) {
                    renderers.add(module);
                    playtoitems.add(Control.getUpnpDisplayName(module));
                }
            }
            //
            // Media Renderer Spinner Select
            Spinner playto = (Spinner) _view.findViewById(R.id.playto);
            playto.setAdapter(playtoitems);
            playto.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                    _selectedMediaRender = null;
                    if (i > 0) {
                        _selectedMediaRender = renderers.get(i - 1);
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> adapterView) {

                }
            });

        }
    });
    //
    browseMediaFolder(lv);

    // Create the AlertDialog object and return it
    _dialog = builder.create();
    _dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialogInterface) {
            _dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
        }
    });
    return _dialog;
}

From source file:com.battlelancer.seriesguide.ui.FixGetGlueCheckInActivity.java

@Override
protected void onCreate(Bundle args) {
    super.onCreate(args);
    setContentView(R.layout.activity_fix_get_glue);
    setupActionBar();/*from w  w w .j a  v  a  2 s.c  o m*/

    setupViews();

    // do not check for null, we want to crash if so
    mShowId = getIntent().getExtras().getString(InitBundle.SHOW_TVDB_ID);

    mAdapter = new GetGlueObjectAdapter(this);
    ListView list = (ListView) findViewById(R.id.listViewGetGlueResults);
    list.addHeaderView(mHeaderView, null, false);
    list.addFooterView(mFooterView, null, false);
    list.setAdapter(mAdapter);
    list.setOnItemClickListener(this);

    // query for show title
    final Cursor show = getContentResolver().query(Shows.buildShowUri(mShowId),
            new String[] { Shows._ID, Shows.TITLE, Shows.GETGLUEID }, null, null, null);
    if (show != null) {
        if (show.moveToFirst()) {
            String glueId = show.getString(2);
            if (!TextUtils.isEmpty(glueId)) {
                mSelectedValue.setText(glueId);
            }

            String query = show.getString(1);

            Bundle loaderArgs = new Bundle();
            loaderArgs.putString("query", query);

            getSupportLoaderManager().initLoader(0, loaderArgs, this);
        }

        show.close();
    }

}

From source file:com.example.android.AudioArchive.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);
    progressDialog = new ProgressDialog(getActivity());
    progressDialog.setIndeterminate(true);
    progressDialog.setTitle("Fetching");
    progressDialog.show();//from w  ww  .  jav  a 2  s.  com
    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
        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.example.demo_dv_fuse.FlightsTab.java

/**
 * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater,
 *      android.view.ViewGroup, android.os.Bundle)
 *///w w  w .j a  v a 2  s  .c  o m
@Override
public View onCreateView(final LayoutInflater layoutInflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    this.inflater = layoutInflater;
    final View flightsTab = this.inflater.inflate(R.layout.flights_tab, container, false);

    final ListView listView = (ListView) flightsTab.findViewById(R.id.flight_details_list);
    final FlightsAdapter adapter = new FlightsAdapter(getActivity(), R.layout.flight_details_row,
            loadFlights());
    listView.setAdapter(adapter);
    listView.setClickable(true);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        /**
         * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView,
         *      android.view.View, int, long)
         */
        @Override
        public void onItemClick(final AdapterView<?> adapterView, final View parent, final int position,
                final long id) {
            handleFlightClicked(position);
        }
    });

    return flightsTab;
}

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

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

    // The ArrayAdapter will take data from a source 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_forecast, // The name of the layout ID.
            R.id.list_item_forecast_textview, // The ID of the textview to populate.
            new ArrayList<String>());

    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() {
            //w ww.j  av a2  s  .c  o m
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
        String forecast = mForecastAdapter.getItem(position);
        Intent intent = new Intent(getActivity(), DetailActivity.class)
                .putExtra(Intent.EXTRA_TEXT, forecast);
        startActivity(intent);
    }
    });*/

    WeatherTimerTask myTask = new WeatherTimerTask();
    Timer myTimer = new Timer();
    myTimer.schedule(myTask, 10000, 300000);

    return rootView;
}

From source file:com.springsource.greenhouse.events.EventDetailsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.event_details);

    final ListView listView = (ListView) findViewById(R.id.event_details_menu);

    String[] menu_items = getResources().getStringArray(R.array.event_details_options_array);
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.menu_list_item, menu_items);
    listView.setAdapter(arrayAdapter);

    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent();

            switch (position) {
            case 0:
                intent.setClass(view.getContext(), EventSessionsFilteredActivity.class);
                break;
            case 1:
                intent.setClass(view.getContext(), EventSessionsScheduleActivity.class);
                break;
            case 2:
                intent.setClass(view.getContext(), PostTweetActivity.class);
                break;
            case 3:
                intent.setClass(view.getContext(), EventTweetsActivity.class);
                break;
            default:
                break;
            }/*from  w w w  .j  a  v  a2s  . c o  m*/

            startActivity(intent);
        }
    });
}

From source file:com.cachirulop.moneybox.fragment.MovementsFragment.java

/**
 * Creates the ListView object to contains the movements information and
 * register the context menu.//from  w w  w  . j av  a 2  s  .  c  o m
 */
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    ListView listView;
    MainActivity parent;

    parent = (MainActivity) getActivity();

    listView = (ListView) parent.findViewById(R.id.lvMovements);
    listView.setAdapter(new MoneyboxMovementAdapter(parent, parent.getCurrentMoneybox()));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            onMovementClick(a, v, position, id);
        }
    });

    registerForContextMenu(listView);

    super.onActivityCreated(savedInstanceState);
}

From source file:com.example.tomk.sunshine.app.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 = {};//w w w . ja va  2s .  co m
    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_forecast, // The name of the layout ID.
            R.id.list_item_forecast_textview, // The ID of the textview to populate.
            weekForecast);

    View rootView = inflater.inflate(R.layout.fragment_my, 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<?> adapterView, View view, int position, long l) {
            String forecast = mForecastAdapter.getItem(position);
            Intent detailIntent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                    forecast);
            startActivity(detailIntent);
        }
    });

    return rootView;
}

From source file:com.arantius.tivocommander.Person.java

private void requestFinished() {
    if (--mOutstandingRequests > 0) {
        return;/*from   ww  w .j  a  v  a  2 s . c  o m*/
    }
    setProgressBarIndeterminateVisibility(false);

    if (mPerson == null || mCredits == null) {
        setContentView(R.layout.no_results);
        return;
    }

    setContentView(R.layout.list_person);

    // Credits.
    JsonNode[] credits = new JsonNode[mCredits.size()];
    int i = 0;
    for (JsonNode credit : mCredits) {
        credits[i++] = credit;
    }

    ListView lv = getListView();
    CreditsAdapter adapter = new CreditsAdapter(Person.this, R.layout.item_person_credits, credits);
    lv.setAdapter(adapter);
    lv.setOnItemClickListener(mOnItemClickListener);

    // Name.
    ((TextView) findViewById(R.id.person_name)).setText(mName);

    // Role.
    JsonNode rolesNode = mPerson.path("roleForPersonId");
    String[] roles = new String[rolesNode.size()];
    for (i = 0; i < rolesNode.size(); i++) {
        roles[i] = rolesNode.path(i).asText();
        roles[i] = Utils.ucFirst(roles[i]);
    }
    ((TextView) findViewById(R.id.person_role)).setText(Utils.join(", ", roles));

    // Birth date.
    TextView birthdateView = ((TextView) findViewById(R.id.person_birthdate));
    if (mPerson.has("birthDate")) {
        Date birthdate = Utils.parseDateStr(mPerson.path("birthDate").asText());
        SimpleDateFormat dateFormatter = new SimpleDateFormat("MMMMM d, yyyy", Locale.US);
        dateFormatter.setTimeZone(TimeZone.getDefault());
        Spannable birthdateStr = new SpannableString("Birthdate: " + dateFormatter.format(birthdate));
        birthdateStr.setSpan(new ForegroundColorSpan(Color.WHITE), 11, birthdateStr.length(), 0);
        birthdateView.setText(birthdateStr);
    } else {
        birthdateView.setVisibility(View.GONE);
    }

    // Birth place.
    TextView birthplaceView = ((TextView) findViewById(R.id.person_birthplace));
    if (mPerson.has("birthPlace")) {
        Spannable birthplaceStr = new SpannableString("Birthplace: " + mPerson.path("birthPlace").asText());
        birthplaceStr.setSpan(new ForegroundColorSpan(Color.WHITE), 12, birthplaceStr.length(), 0);
        birthplaceView.setText(birthplaceStr);
    } else {
        birthplaceView.setVisibility(View.GONE);
    }

    ImageView iv = (ImageView) findViewById(R.id.person_image);
    View pv = findViewById(R.id.person_image_progress);
    String imgUrl = Utils.findImageUrl(mPerson);
    new DownloadImageTask(this, iv, pv).execute(imgUrl);
}

From source file:com.davila.sunshine.app.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<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_forecast, // The name of the layout ID.
            R.id.list_item_forecast_textview, // The ID of the textview to populate.
            weekForecast);//  w  w w.  ja v 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);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String forecast = mForecastAdapter.getItem(position);
            Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                    forecast);
            startActivity(intent);
            //Toast.makeText(getActivity(), forecast, Toast.LENGTH_SHORT).show();

        }
    });

    return rootView;
}