List of usage examples for android.widget ListView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:com.cerema.cloud2.ui.activity.ErrorsWhileCopyingHandlerActivity.java
/** * {@link}//from w w w . j ava 2s . co m */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /// read extra parameters in intent Intent intent = getIntent(); mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT); mRemotePaths = intent.getStringArrayListExtra(EXTRA_REMOTE_PATHS); mLocalPaths = intent.getStringArrayListExtra(EXTRA_LOCAL_PATHS); mStorageManager = new FileDataStorageManager(mAccount, getContentResolver()); mHandler = new Handler(); if (mCurrentDialog != null) { mCurrentDialog.dismiss(); mCurrentDialog = null; } /// load generic layout setContentView(R.layout.generic_explanation); /// customize text message TextView textView = (TextView) findViewById(R.id.message); String appName = getString(R.string.app_name); String message = String.format(getString(R.string.sync_foreign_files_forgotten_explanation), appName, appName, appName, appName, mAccount.name); textView.setText(message); textView.setMovementMethod(new ScrollingMovementMethod()); /// load the list of local and remote files that failed ListView listView = (ListView) findViewById(R.id.list); if (mLocalPaths != null && mLocalPaths.size() > 0) { mAdapter = new ErrorsWhileCopyingListAdapter(); listView.setAdapter(mAdapter); } else { listView.setVisibility(View.GONE); mAdapter = null; } /// customize buttons Button cancelBtn = (Button) findViewById(R.id.cancel); Button okBtn = (Button) findViewById(R.id.ok); okBtn.setText(R.string.foreign_files_move); cancelBtn.setOnClickListener(this); okBtn.setOnClickListener(this); }
From source file:com.example.amit.tellymoviebuzzz.PopularSeriesFragment.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 PopularSeriesAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.popularseries_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_popular_series); listView.setAdapter(mForecastAdapter); // We'll call our MainActivity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override// w w w .ja v a 2s. c om 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 = "upcoming"; Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); // 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, "87101")); startActivity(intent); } } }); return rootView; }
From source file:com.example.listviewanimationdemo.AnimateDismissActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_animateremoval); mSelectedPositions = new ArrayList<Integer>(); ListView listView = (ListView) findViewById(R.id.activity_animateremoval_listview); mAdapter = new MyListAdapter(BaseListActivity.getItems()); final AnimateDismissAdapter animateDismissAdapter = new AnimateDismissAdapter(mAdapter, new MyOnDismissCallback()); animateDismissAdapter.setAbsListView(listView); listView.setAdapter(animateDismissAdapter); Button button = (Button) findViewById(R.id.activity_animateremoval_button); button.setOnClickListener(new OnClickListener() { @Override/* w w w . ja v a 2 s . c om*/ public void onClick(final View v) { animateDismissAdapter.animateDismiss(mSelectedPositions); mSelectedPositions.clear(); } }); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { CheckedTextView tv = (CheckedTextView) view; tv.toggle(); if (tv.isChecked()) { mSelectedPositions.add(position); } else { mSelectedPositions.remove((Integer) position); } } }); }
From source file:com.example.mihai.inforoute.app.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); mRouteAdapter = new RouteAdapter(getActivity(), null, 0); 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/*from www . j a v a 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) { Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(RouteContract.WeatherEntry.buildWeatherLocationWithDate(arrivalCity, cursor.getLong(COL_WEATHER_DATE))); startActivity(intent); } } }); return rootView; }
From source file:com.bti360.hackathon.listview.HackathonActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from ww w . j a v a2 s. c o m*/ //Let's create a String List and retrieve the String Array from our Resources mNames = new ArrayList<String>(); mNames.addAll(Arrays.asList(getResources().getStringArray(R.array.names))); //grab the ListView ListView lv = (ListView) findViewById(R.id.listView1); //create a new ListAdapter and pass in our ArrayList of data mAdapter = new NameAdapter(this, R.layout.list_item, mNames); lv.setAdapter(mAdapter); //grab our button and set an onClickListener Button addButton = (Button) findViewById(R.id.button1); addButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { /*when the add button is clicked we will show the Add Dialog. * Opening a Dialog with showDialog causes the Activity to Manage the * dialog meaning it will control the lifecycle - create, show, hide, * destroy when Activity is killed, etc. */ showDialog(ADD_DIALOG); } }); }
From source file:com.nest5.businessClient.AccountsActivity.java
/** * Sets up the 'connect' screen content. *///w w w . ja va 2s.c o m private void setConnectScreenContent() { List<String> accounts = getGoogleAccounts(); if (accounts.size() == 0) { // Show a dialog and invoke the "Add Account" activity if requested AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage(R.string.needs_account); builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT)); } }); builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); } }); builder.setIcon(android.R.drawable.stat_sys_warning); builder.setTitle(R.string.attention); builder.show(); } else { final ListView listView = (ListView) findViewById(R.id.select_account); listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); listView.setItemChecked(mAccountSelectedPosition, true); final Button connectButton = (Button) findViewById(R.id.connect); connectButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // Set "connecting" status SharedPreferences prefs = Util.getSharedPreferences(mContext); prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit(); // Get account name mAccountSelectedPosition = listView.getCheckedItemPosition(); TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition); // Register register((String) account.getText()); finish(); } }); } // internetConnectionStatus = (ImageView) findViewById(R.id.header_connection_status); SharedPreferences prefs = Util.getSharedPreferences(mContext); if (!isNetworkAvailable()) { internetConnectionStatus.setImageResource(R.drawable.error); prefs.edit().putInt(Util.INTERNET_CONNECTION, Util.INTERNET_DISCONNECTED).commit(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage( "No tienes una conexin a internet activa. Habiltala haciendo click en aceptar y seleccionando luego una red.") .setCancelable(false).setPositiveButton("Aceptar", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS); startActivityForResult(intent, 1); } }).setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { finish(); } }).show(); } else { prefs.edit().putInt(Util.INTERNET_CONNECTION, Util.INTERNET_CONNECTED).commit(); } }
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView = (ListView) findViewById(R.id.list); List sensorList = new ArrayList<String>(); List<Sensor> sensors = ((SensorManager) getSystemService(Context.SENSOR_SERVICE)) .getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensors) { sensorList.add(sensor.getName()); }/*from w w w .ja v a 2s . c om*/ ListAdapter sensorAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, sensorList); listView.setAdapter(sensorAdapter); }
From source file:com.dsi.ant.antplus.pluginsampler.geocache.Activity_GeoScanList.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_device_list); tv_status = (TextView) findViewById(R.id.textView_Status); deviceList_Display = new ArrayList<Map<String, String>>(); adapter_deviceList_Display = new SimpleAdapter(this, deviceList_Display, android.R.layout.simple_list_item_2, new String[] { "title", "desc" }, new int[] { android.R.id.text1, android.R.id.text2 }); ListView listView_Devices = (ListView) findViewById(R.id.listView_deviceList); listView_Devices.setAdapter(adapter_deviceList_Display); //Set the list to download the data for the selected device and display it. listView_Devices.setOnItemClickListener(new OnItemClickListener() { @Override//from w w w . j ava2s. c om public void onItemClick(AdapterView<?> parent, View view, int pos, long id) { if (geoPcc == null) return; if (!bDevicesInList) return; int deviceID = Integer.parseInt(deviceList_Display.get(pos).get("desc")); final Dialog_ProgressWaiter progressDialog = new Dialog_ProgressWaiter("Downloading device data"); boolean reqSubmitted = geoPcc.requestDeviceData(deviceID, true, //Display the results if successful or report failures to user new IDataDownloadFinishedReceiver() { @Override public void onNewDataDownloadFinished(GeocacheRequestStatus status, GeocacheDeviceData downloadedData) { StringBuilder error = new StringBuilder("Error Downloading Data: "); switch (status) { case SUCCESS: final Dialog_GeoDeviceDetails detailsDialog = new Dialog_GeoDeviceDetails( geoPcc, downloadedData); runOnUiThread(new Runnable() { @Override public void run() { progressDialog.dismiss(); detailsDialog.show(getSupportFragmentManager(), "DeviceDetails"); } }); return; case FAIL_DEVICE_NOT_IN_LIST: error.append("Device no longer in list"); break; case FAIL_ALREADY_BUSY_EXTERNAL: error.append("Device is busy"); break; case FAIL_DEVICE_COMMUNICATION_FAILURE: error.append("Communication with device failed"); break; case UNRECOGNIZED: runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(Activity_GeoScanList.this, "Failed: UNRECOGNIZED. PluginLib Upgrade Required?", Toast.LENGTH_SHORT).show(); } }); break; default: break; } final String errorStr = error.toString(); runOnUiThread(new Runnable() { @Override public void run() { progressDialog.dismiss(); Toast.makeText(Activity_GeoScanList.this, errorStr, Toast.LENGTH_LONG) .show(); } }); } }, progressDialog.getUpdateReceiver()); if (reqSubmitted) progressDialog.show(getSupportFragmentManager(), "DownloadProgressDialog"); else Toast.makeText(Activity_GeoScanList.this, "Error Downloading Data: PCC already busy or dead", Toast.LENGTH_SHORT).show(); } }); resetPcc(); }
From source file:com.example.listviewanimationdemo.itemmanipulation.AnimateDismissActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle("item"); setContentView(R.layout.activity_animateremoval); mSelectedPositions = new ArrayList<Integer>(); ListView listView = (ListView) findViewById(R.id.activity_animateremoval_listview); mAdapter = new MyListAdapter(BaseListActivity.getItems()); final AnimateDismissAdapter animateDismissAdapter = new AnimateDismissAdapter(mAdapter, new MyOnDismissCallback()); animateDismissAdapter.setAbsListView(listView); listView.setAdapter(animateDismissAdapter); Button button = (Button) findViewById(R.id.activity_animateremoval_button); button.setOnClickListener(new OnClickListener() { @Override//w ww . j a v a2s .c om public void onClick(final View v) { animateDismissAdapter.animateDismiss(mSelectedPositions); mSelectedPositions.clear(); } }); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { CheckedTextView tv = (CheckedTextView) view; tv.toggle(); if (tv.isChecked()) { mSelectedPositions.add(position); } else { mSelectedPositions.remove((Integer) position); } } }); }
From source file:com.example.android.gft.ColorsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.word_list, container, false); // Create and setup the {@link AudioManager} to request audio focus mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); // Create a list of words final ArrayList<Word> words = new ArrayList<Word>(); words.add(new Word(R.string.color_red, R.string.miwok_color_red, R.drawable.color_red, R.raw.color_red)); words.add(new Word(R.string.color_mustard_yellow, R.string.miwok_color_mustard_yellow, R.drawable.color_mustard_yellow, R.raw.color_mustard_yellow)); words.add(new Word(R.string.color_dusty_yellow, R.string.miwok_color_dusty_yellow, R.drawable.color_dusty_yellow, R.raw.color_dusty_yellow)); words.add(new Word(R.string.color_green, R.string.miwok_color_green, R.drawable.color_green, R.raw.color_green));//from w w w. jav a 2 s . c o m words.add(new Word(R.string.color_brown, R.string.miwok_color_brown, R.drawable.color_brown, R.raw.color_brown)); words.add( new Word(R.string.color_gray, R.string.miwok_color_gray, R.drawable.color_gray, R.raw.color_gray)); words.add(new Word(R.string.color_black, R.string.miwok_color_black, R.drawable.color_black, R.raw.color_black)); words.add(new Word(R.string.color_white, R.string.miwok_color_white, R.drawable.color_white, R.raw.color_white)); // Create an {@link WordAdapter}, whose data source is a list of {@link Word}s. The // adapter knows how to create list items for each item in the list. WordAdapter adapter = new WordAdapter(getActivity(), words, R.color.category_colors); // Find the {@link ListView} object in the view hierarchy of the {@link Activity}. // There should be a {@link ListView} with the view ID called list, which is declared in the // word_list.xml layout file. ListView listView = (ListView) rootView.findViewById(R.id.list); // Make the {@link ListView} use the {@link WordAdapter} we created above, so that the // {@link ListView} will display list items for each {@link Word} in the list. listView.setAdapter(adapter); // Set a click listener to play the audio when the list item is clicked on listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // Release the media player if it currently exists because we are about to // play a different sound file releaseMediaPlayer(); // Get the {@link Word} object at the given position the user clicked on Word word = words.get(position); // Request audio focus so in order to play the audio file. The app needs to play a // short audio file, so we will request audio focus with a short amount of time // with AUDIOFOCUS_GAIN_TRANSIENT. int result = mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { // We have audio focus now. // Create and setup the {@link MediaPlayer} for the audio resource associated // with the current word mMediaPlayer = MediaPlayer.create(getActivity(), word.getAudioResourceId()); // Start the audio file mMediaPlayer.start(); // Setup a listener on the media player, so that we can stop and release the // media player once the sound has finished playing. mMediaPlayer.setOnCompletionListener(mCompletionListener); } } }); return rootView; }