List of usage examples for android.widget ListView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:com.example.android.miwok.activity.NumbersActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.word_list);/*from ww w . j a va2s.c o m*/ //Create and setup the {@link AudioManager} to request audio focus mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // Create a list of words //made the arraylist final so that it could be accessed inside the onItemClick method. final ArrayList<Word> words = new ArrayList<Word>(); words.add(new Word("one", "lutti", R.drawable.number_one, R.raw.number_one)); words.add(new Word("two", "otiiko", R.drawable.number_two, R.raw.number_two)); words.add(new Word("three", "tolookosu", R.drawable.number_three, R.raw.number_three)); words.add(new Word("four", "oyyisa", R.drawable.number_four, R.raw.number_four)); words.add(new Word("five", "massokka", R.drawable.number_five, R.raw.number_five)); words.add(new Word("six", "temmokka", R.drawable.number_six, R.raw.number_six)); words.add(new Word("seven", "kenekaku", R.drawable.number_seven, R.raw.number_seven)); words.add(new Word("eight", "kawinta", R.drawable.number_eight, R.raw.number_eight)); words.add(new Word("nine", "woe", R.drawable.number_nine, R.raw.number_nine)); words.add(new Word("ten", "naaacha", R.drawable.number_ten, R.raw.number_ten)); // 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(this, words); // 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) findViewById(R.id.list); //listView.setBackgroundColor(R.color.category_numbers); listView.setBackgroundColor(Color.parseColor("#FD8E09")); // 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); //plays the audio for number one when any item in the list is clicked click listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //release current resources being used for media player if it currently exists //because we are about to play a different sound file. releaseMediaPlayer(); //get the word located in the list that is at same position as the item clicked in the list Word currentWord = words.get(position); // Request audio focus for playback int result = mAudioManager.requestAudioFocus(mAudioFocusChangeListener, // Use the music stream. AudioManager.STREAM_MUSIC, // Request temporary focus. AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { //create the medial player with the audio file that is stored in the list for that word. mMediaPlayer = MediaPlayer.create(getApplicationContext(), currentWord.getmMiwokAudio()); //play the file mMediaPlayer.start(); //listener to stop and release the media player and resources being used // once the sounds has finished playing mMediaPlayer.setOnCompletionListener(mCompletionListener); } } }); }
From source file:com.Candy.sizer.CandySizer.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final ImageView delButton = (ImageView) getView().findViewById(R.id.btn_delete); final ImageView profileButton = (ImageView) getView().findViewById(R.id.btn_profile); if (delButton == null) { return;//from ww w . j av a 2 s . co m } // create arraylist of apps not to be removed final ArrayList<String> safetyList = new ArrayList<String>(); safetyList.add("BackupRestoreConfirmation.apk"); safetyList.add("CertInstaller.apk"); safetyList.add("Contacts.apk"); safetyList.add("ContactsProvider.apk"); safetyList.add("DefaultContainerService.apk"); safetyList.add("DownloadProvider.apk"); safetyList.add("DrmProvider.apk"); safetyList.add("MediaProvider.apk"); safetyList.add("Mms.apk"); safetyList.add("PackageInstaller.apk"); safetyList.add("Phone.apk"); safetyList.add("Settings.apk"); safetyList.add("SettingsProvider.apk"); safetyList.add("CandyOTA.apk"); safetyList.add("Superuser.apk"); safetyList.add("SystemUI.apk"); safetyList.add("TelephonyProvider.apk"); // create arraylist from /system/app content File system = new File(systemPath); String[] sysappArray = system.list(); mSysApp = new ArrayList<String>(Arrays.asList(sysappArray)); // remove "apps not to be removed" from list and sort list mSysApp.removeAll(safetyList); Collections.sort(mSysApp); // populate listview via arrayadapter adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_multiple_choice, mSysApp); final ListView lv = (ListView) getView().findViewById(R.string.listsystem); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); lv.setAdapter(adapter); // longclick an entry lv.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) { // create deletion dialog String item = lv.getAdapter().getItem(arg2).toString(); showDialog(DELETE_DIALOG, item, adapter, 0); return false; } }); // click button delete delButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // check which items are selected String item = null; int itemCounter = 0; SparseBooleanArray checked = lv.getCheckedItemPositions(); for (int i = lv.getCount() - 1; i > 0; i--) { if (checked.get(i)) { item = mSysApp.get(i); itemCounter++; } } if (item == null) { toast(getResources().getString(R.string.sizer_message_noselect)); return; } else { showDialog(DELETE_MULTIPLE_DIALOG, item, adapter, itemCounter); } } }); // click button profile profileButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // call select dialog selectDialog(mSysApp, adapter); } }); }
From source file:com.artur.softwareproject.Main.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.d(TAG, "onCreate was called."); recordClock = (TextView) findViewById(R.id.recordClock); ListView sensorDataList = (ListView) findViewById(R.id.dataList); adapter = new SensorDataListAdapter(this, dataTypes, dataUnits); sensorDataList.setAdapter(adapter); disconnect = 0;// ww w . ja v a 2 s .com modelConstructed = false; gpsStatus = false; LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(disconnectReceive, new IntentFilter("disconnectFilter")); LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(gpsStatusReceive, new IntentFilter("gpsStatusFilter")); bluetoothServiceIntent = new Intent(this, BluetoothService.class); posServiceIntent = new Intent(this, PositionService.class); startService(posServiceIntent); }
From source file:com.example.mysteryhunt.UserActivity.java
private void showAttributes() { final UserAttributesAdapter attributesAdapter = new UserAttributesAdapter(getApplicationContext()); final ListView attributesListView; attributesListView = (ListView) findViewById(R.id.listViewUserAttributes); attributesListView.setAdapter(attributesAdapter); attributesList = attributesListView; attributesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/* ww w . j ava2s . c o m*/ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TextView data = (TextView) view.findViewById(R.id.editTextUserDetailInput); String attributeType = data.getHint().toString(); String attributeValue = data.getText().toString(); showUserDetail(attributeType, attributeValue); } }); }
From source file:com.fabioarias.ui.Store.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = null;/* w w w. ja va 2 s .c o m*/ if (((MainActivity) getActivity()).getCartSize() > 0) { v = inflater.inflate(R.layout.store, null); setupViewComponents(v); } else { if (((MainActivity) getActivity()).getLastpurchase().length() == 0) { v = inflater.inflate(R.layout.cart_empty, null); } else { v = inflater.inflate(R.layout.job, null); ListView grid = (ListView) v.findViewById(R.id.list); imgJob = (ImageView) v.findViewById(R.id.qrJobCode); grid.setAdapter(new JobAdapter(((MainActivity) getActivity()).getLastpurchase())); } } return v; }
From source file:com.digium.respoke.GroupListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_group_list); setTitle(ContactManager.sharedInstance().username); listAdapter = new ListDataAdapter(); ListView lv = (ListView) findViewById(R.id.group_list); //retrieve the instance of the ListView from your main layout lv.setAdapter(listAdapter); //assign the Adapter to be used by the ListView lv.setOnItemClickListener(this); ContactManager.sharedInstance().sharedClient.setListener(this); // set the initial status for this client setStatus("available"); }
From source file:org.bishoph.oxdemo.OXDemo.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_oxdemo); // Upon interacting with UI controls, delay any scheduled hide() // operations to prevent the jarring behavior of controls going away // while interacting with the UI. Button button = (Button) findViewById(R.id.start_button); // button.setOnTouchListener(mDelayHideTouchListener); // Add OnClickListener to button button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startVoiceRecognitionActivity(); }/*from w ww . ja v a 2 s . c om*/ }); prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); prefs.registerOnSharedPreferenceChangeListener(this); listentries = new ListEntries(); listview = (ListView) findViewById(R.id.listView1); listviewarray = new ArrayList<String>(); listviewarray.add("Loading ... please wait"); listviewadapter = new CustomArrayAdapter(this, R.layout.mysimplelistitem, listviewarray); listview.setAdapter(listviewadapter); SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(listview, new DismissCallbacks() { public void onDismiss(ListView listView, int[] reverseSortedPositions) { for (int position : reverseSortedPositions) { Log.v("OXDemo", "Preparing for deletion " + listviewadapter.getItem(position)); removeTask(position); } listviewadapter.notifyDataSetChanged(); } @Override public boolean canDismiss(int position) { return true; } }); listview.setOnTouchListener(touchListener); listview.setOnScrollListener(touchListener.makeScrollListener()); }
From source file:com.airad.zhonghan.PullToRefreshListFragmentActivity.java
/** Called when the activity is first created. */ @Override//from ww w . ja v a 2s . c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_list_fragment); mPullRefreshListFragment = (PullToRefreshListFragment) getSupportFragmentManager() .findFragmentById(R.id.frag_ptr_list); // Get PullToRefreshListView from Fragment mPullRefreshListView = mPullRefreshListFragment.getPullToRefreshListView(); // Set a listener to be invoked when the list should be refreshed. mPullRefreshListView.setOnRefreshListener(this); // You can also just use mPullRefreshListFragment.getListView() ListView actualListView = mPullRefreshListView.getRefreshableView(); mListItems = new LinkedList<String>(); mListItems.addAll(Arrays.asList(mStrings)); mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems); ImageView img = new ImageView(this); img.setImageResource(R.drawable.ic_action_search); actualListView.addHeaderView(img); // You can also just use setListAdapter(mAdapter) or // mPullRefreshListView.setAdapter(mAdapter) actualListView.setAdapter(mAdapter); mPullRefreshListFragment.setListShown(true); }
From source file:com.coderdojo.libretalk.MainActivity.java
private final void printMsg(final String message) { ArrayAdapter<SpannableString> adapter = new ArrayAdapter<SpannableString>(this, android.R.layout.simple_list_item_1, mMessageListArray); ListView listView = (ListView) findViewById(R.id.message_list); listView.setAdapter(adapter); listView.setStackFromBottom(true);//from w w w . java 2 s . c o m mMessageListArray.add(new SpannableString(message)); adapter.notifyDataSetChanged(); }
From source file:ota.otaupdates.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); if (sharedPreferences.getBoolean("force_english", false)) { Locale myLocale = new Locale("en"); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale;/* w w w . j a v a2 s . c o m*/ res.updateConfiguration(conf, dm); } if (sharedPreferences.getBoolean("apptheme_light", false)) setTheme(R.style.AppTheme_Light); else setTheme(R.style.AppTheme_Dark); setContentView(R.layout.activity_main); build_url .append((Utils.doesPropExist(Constants.URL_PROP)) ? Utils.getProp(Constants.URL_PROP) : getString(R.string.download_url)) .append("/api/").append(Build.DEVICE).append("/").append(Build.TIME / 1000); build_dl_url.append((Utils.doesPropExist(Constants.URL_PROP)) ? Utils.getProp(Constants.URL_PROP) : getString(R.string.download_url)).append("/builds/"); delta_url.append((Utils.doesPropExist(Constants.URL_PROP) ? Utils.getProp(Constants.URL_PROP) : getString(R.string.download_url))).append("/delta/").append(Build.VERSION.INCREMENTAL); delta_dl_url.append((Utils.doesPropExist(Constants.URL_PROP)) ? Utils.getProp(Constants.URL_PROP) : getString(R.string.download_url)).append("/deltas/"); otaList = new ArrayList<>(); get_builds(); pb = (ProgressBar) findViewById(R.id.pb); pb.setVisibility(View.VISIBLE); final ListView ota_list = (ListView) findViewById(R.id.ota_list); adapter = new OTAUpdatesAdapter(getApplicationContext(), R.layout.row, otaList); ota_list.setAdapter(adapter); final CoordinatorLayout coordinator_root = (CoordinatorLayout) findViewById(R.id.coordinator_root); ota_list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, final int position, long id) { final String url = build_dl_url.toString() + otaList.get(position).getOta_filename(); if (Build.VERSION.SDK_INT >= 23 && !checkPermission()) allow_write_sd(); else if (sharedPreferences.getBoolean("disable_mobile", true) && isMobileDataEnabled()) { sb_network = Snackbar.make(coordinator_root, getString(R.string.disable_mobile_message), Snackbar.LENGTH_SHORT); sb_network.getView() .setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorSecond)); sb_network.show(); } else { new Thread(new Runnable() { @Override public void run() { create_notification(1, getString(R.string.app_name), getString( R.string.downloader_notification, otaList.get(position).getOta_filename())); Utils.DownloadFromUrl(url, otaList.get(position).getOta_filename()); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancel(1); runOnUiThread(new Runnable() { @Override public void run() { if (MD5.checkMD5(otaList.get(position).getOta_md5(), new File(DL_PATH + otaList.get(position).getOta_filename())) || !sharedPreferences.getBoolean("md5_checking", true)) trigger_autoinstall(DL_PATH + otaList.get(position).getOta_filename()); else { new AlertDialog.Builder(MainActivity.this) .setTitle(getString(R.string.md5_title)) .setMessage(getString(R.string.md5_message)).setNeutralButton( R.string.button_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }) .show(); } } }); } }).start(); } } }); }