List of usage examples for android.widget ListView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:com.example.amit.tellymoviebuzzz.PopularFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new PopularAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.popular_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_popular_movies); listView.setAdapter(mForecastAdapter); // We'll call our MainActivity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from ww w.ja va2 s.c o m public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { // String locationSetting = Utility.getPreferredLocation(getActivity()); String movieSetting = "thisyear"; //Utility.getPreferredMovie(getActivity()); // Intent intent = new Intent(getActivity(), DetailActivity.class) // .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate( // locationSetting, cursor.getLong(COL_WEATHER_DATE) // )); Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting, cursor.getString(COL_MOVIE_SETTING))); startActivity(intent); } } }); return rootView; }
From source file:com.example.android.supportv4.media.BrowseFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_list, container, false); mBrowserAdapter = new BrowseAdapter(getActivity(), mMediaItems); View controls = rootView.findViewById(R.id.controls); controls.setVisibility(View.GONE); ListView listView = (ListView) rootView.findViewById(R.id.list_view); listView.setAdapter(mBrowserAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*from w w w. ja v a2s . c o m*/ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { MediaBrowserCompat.MediaItem item = mBrowserAdapter.getItem(position); try { FragmentDataHelper listener = (FragmentDataHelper) getActivity(); listener.onMediaItemSelected(item); } catch (ClassCastException ex) { Log.e(TAG, "Exception trying to cast to FragmentDataHelper", ex); } } }); Bundle args = getArguments(); mMediaId = args.getString(ARG_MEDIA_ID, null); mMediaBrowser = new MediaBrowserCompat(getActivity(), new ComponentName(getActivity(), MediaBrowserServiceSupport.class), mConnectionCallback, null); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (mCanLoadNewPage && firstVisibleItem + visibleItemCount == totalItemCount) { mCanLoadNewPage = false; loadPage((mMediaItems.size() + PAGE_SIZE - 1) / PAGE_SIZE); } } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { // Do nothing } }); return rootView; }
From source file:com.example.cgraham.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<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);/*from www . j a v a 2 s .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.listview_forecast); listView.setAdapter(mForecastAdapter); return rootView; }
From source file:com.example.amit.tellymoviebuzzz.ThisYearFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new ThisYearAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.thisyear_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_movies_thisyear); listView.setAdapter(mForecastAdapter); // We'll call our MainActivity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//w ww . j a va 2 s. co m public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { // String locationSetting = Utility.getPreferredLocation(getActivity()); String movieSetting = "thisyear"; //Utility.getPreferredMovie(getActivity()); // Intent intent = new Intent(getActivity(), DetailActivity.class) // .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate( // locationSetting, cursor.getLong(COL_WEATHER_DATE) // )); Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting, cursor.getString(COL_MOVIE_SETTING))); startActivity(intent); } } }); return rootView; }
From source file:com.example.amit.tellymoviebuzzz.WatchlistMovieForecast.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new WatchlistMovieAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.watchlist_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_watchlist_thisyear); listView.setAdapter(mForecastAdapter); // We'll call our MainActivity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/* w ww. ja va 2 s.co m*/ public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { // String locationSetting = Utility.getPreferredLocation(getActivity()); String movieSetting = "thisyear"; //Utility.getPreferredMovie(getActivity()); // Intent intent = new Intent(getActivity(), DetailActivity.class) // .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate( // locationSetting, cursor.getLong(COL_WEATHER_DATE) // )); Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting, cursor.getString(COL_MOVIE_SETTING))); startActivity(intent); } } }); return rootView; }
From source file:com.example.android.supportv4.media.QueueFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_list, container, false); mSkipPrevious = (ImageButton) rootView.findViewById(R.id.skip_previous); mSkipPrevious.setEnabled(false);/*from w ww.j a va2s . c o m*/ mSkipPrevious.setOnClickListener(mButtonListener); mSkipNext = (ImageButton) rootView.findViewById(R.id.skip_next); mSkipNext.setEnabled(false); mSkipNext.setOnClickListener(mButtonListener); mPlayPause = (ImageButton) rootView.findViewById(R.id.play_pause); mPlayPause.setEnabled(true); mPlayPause.setOnClickListener(mButtonListener); mQueueAdapter = new QueueAdapter(getActivity()); ListView mListView = (ListView) rootView.findViewById(R.id.list_view); mListView.setAdapter(mQueueAdapter); mListView.setFocusable(true); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { MediaSessionCompat.QueueItem item = mQueueAdapter.getItem(position); mTransportControls.skipToQueueItem(item.getQueueId()); } }); mMediaBrowser = new MediaBrowserCompat(getActivity(), new ComponentName(getActivity(), MediaBrowserServiceSupport.class), mConnectionCallback, null); return rootView; }
From source file:com.example.pawandeep.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);// ww w . j a v a2 s . 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<?> adapterView, View view, int i, long l) { Context context = ForecastFragment.this.getActivity(); CharSequence text = "Hello toast!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } }); return rootView; }
From source file:cl.smartcities.isci.transportinspector.dialogs.BusSelectionDialog.java
@NonNull @Override//from w w w . j a v a2s.c o m public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog dialog; AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); LayoutInflater inflater = this.getActivity().getLayoutInflater(); final View dialog_view = inflater.inflate(R.layout.bus_selection_dialog, null); final Typeface iconTypeface = Typeface.createFromAsset(this.getContext().getAssets(), getActivity().getString(R.string.icon_font)); ((TextView) dialog_view.findViewById(R.id.suggestion_icon)).setTypeface(iconTypeface); builder.setView(dialog_view); builder.setCancelable(false); dialog = builder.create(); final Bundle bundle = getArguments(); ArrayList<Bus> buses = null; if (bundle != null) { buses = bundle.getParcelableArrayList(NotificationState.BUSES); } if (buses != null && !buses.isEmpty()) { dialog_view.findViewById(R.id.list_view).setVisibility(View.VISIBLE); setBusMap(buses); ArrayList<String> serviceList = new ArrayList<>(); serviceList.addAll(this.busMap.keySet()); BusSelectionAdapter adapter = new BusSelectionAdapter(this.getContext(), serviceList, busMap, new BusSelectionAdapter.ListViewAdapterListener() { @Override public void onPositiveClick(Bus bus) { dialog.cancel(); listener.onPositiveClick(bus); } @Override public void onNegativeClick() { dialog.cancel(); listener.onNegativeClick(); } }); ListView listView = (ListView) dialog_view.findViewById(R.id.list_view); listView.setAdapter(adapter); if (adapter.getCount() > VISIBLE_BUSES) { View item = adapter.getView(0, null, listView); item.measure(0, 0); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, (int) ((VISIBLE_BUSES + 0.5) * item.getMeasuredHeight())); listView.setLayoutParams(params); } } Button otherAcceptButton = (Button) dialog_view.findViewById(R.id.accept); otherAcceptButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText serviceEditText = (EditText) dialog_view.findViewById(R.id.service_edit_text); EditText licensePlateEditText = (EditText) dialog_view.findViewById(R.id.license_plate_edit_text); String service = serviceEditText.getText().toString(); String licensePlate = licensePlateEditText.getText().toString(); ServiceHelper helper = new ServiceHelper(getContext()); if (ServiceValidator.validate(service) && helper.getColorId(Util.formatServiceName(service)) != 0) { service = Util.formatServiceName(service); if (licensePlate.equals("")) { licensePlate = Constants.DUMMY_LICENSE_PLATE; } else if (!LicensePlateValidator.validate(licensePlate)) { Toast.makeText(getContext(), R.string.bus_selection_warning_plate, Toast.LENGTH_SHORT) .show(); return; } } else { Toast.makeText(getContext(), R.string.bus_selection_warning_service, Toast.LENGTH_SHORT).show(); return; } final Bus bus = new Bus(Util.formatServiceName(service), licensePlate); InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); Log.d("BusSelectionDialog", "hiding soft input"); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { BusSelectionDialog.this.getActivity().runOnUiThread(new Runnable() { @Override public void run() { dialog.cancel(); listener.onPositiveClick(bus); } }); } }, 500); //dialog.cancel(); // TODO(aantoine): This call is to quick, some times the keyboard is not // out of the window when de sliding panel shows up. //listener.onPositiveClick(bus); } }); /* set cancel button to close dialog */ dialog_view.findViewById(R.id.close_dialog).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); listener.onNegativeClick(); } }); ((Button) dialog_view.findViewById(R.id.close_dialog)).setTypeface(iconTypeface); dialog.setCanceledOnTouchOutside(false); return dialog; }
From source file:com.example.android.mediabrowserservice.QueueFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_list, container, false); mSkipPrevious = (ImageButton) rootView.findViewById(R.id.skip_previous); mSkipPrevious.setEnabled(false);/* ww w . j a v a 2 s . co m*/ mSkipPrevious.setOnClickListener(mButtonListener); mSkipNext = (ImageButton) rootView.findViewById(R.id.skip_next); mSkipNext.setEnabled(false); mSkipNext.setOnClickListener(mButtonListener); mPlayPause = (ImageButton) rootView.findViewById(R.id.play_pause); mPlayPause.setEnabled(true); mPlayPause.setOnClickListener(mButtonListener); mQueueAdapter = new QueueAdapter(getActivity()); ListView mListView = (ListView) rootView.findViewById(R.id.list_view); mListView.setAdapter(mQueueAdapter); mListView.setFocusable(true); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { MediaSessionCompat.QueueItem item = mQueueAdapter.getItem(position); mTransportControls.skipToQueueItem(item.getQueueId()); } }); mMediaBrowser = new MediaBrowserCompat(getActivity(), new ComponentName(getActivity(), MusicService.class), mConnectionCallback, null); return rootView; }
From source file:com.hybris.mobile.app.commerce.fragment.OrderDetailFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mOrderDetailNumber = (TextView) getView().findViewById(R.id.order_detail_number_text); mOrderDetailDatePlaced = (TextView) getView().findViewById(R.id.order_detail_date_placed_text); mOrderDetailSatus = (TextView) getView().findViewById(R.id.order_detail_status_text); Button mCloseOrdertDetailButton = (Button) getView().findViewById(R.id.order_detail_exit); mCloseOrdertDetailButton.setOnClickListener(exitOrderDetailButtonListener); // Product list ListView productList = (ListView) getActivity().findViewById(R.id.order_products_list); mOrderProductListAdapter = new OrderProductListAdapter(getActivity(), new ArrayList<OrderEntry>()); productList.setAdapter(mOrderProductListAdapter); }