List of usage examples for android.widget ListView getAdapter
@Override
public ListAdapter getAdapter()
From source file:com.liferay.alerts.activity.CommentsActivity.java
private void _registerBroadcastReceiver() { IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_ADD_COMMENT); filter.addAction(ACTION_UPDATE_COMMENTS_LIST); _receiver = new BroadcastReceiver() { @Override//from w w w .ja v a 2 s . co m public void onReceive(Context context, Intent intent) { String action = intent.getAction(); ListView listView = (ListView) findViewById(R.id.comments); if (ACTION_UPDATE_COMMENTS_LIST.equals(action)) { ArrayList<Alert> alerts = intent.getParcelableArrayListExtra(EXTRA_ALERTS); ArrayAdapter<Alert> adapter = new CommentListAdapter(getApplicationContext(), alerts); listView.setAdapter(adapter); } else if (ACTION_ADD_COMMENT.equals(action)) { Alert alert = intent.getParcelableExtra(EXTRA_ALERT); ArrayAdapter<Alert> adapter = (ArrayAdapter<Alert>) listView.getAdapter(); adapter.add(alert); } } }; _getBroadcastManager().registerReceiver(_receiver, filter); }
From source file:com.tweetlanes.android.core.view.UserFeedFragment.java
@Override public void onJumpToTop() { if (mUserFeedListView != null) { ListView listView = mUserFeedListView.getRefreshableView(); if (listView != null && listView.getAdapter() != null && !listView.getAdapter().isEmpty()) { listView.setSelection(0);/*w ww . j a v a2 s .c o m*/ } } }
From source file:android.support.v7.view.menu.CascadingMenuPopup.java
/** * Attempts to find the view for the menu item that owns the specified * submenu.//from w w w. j a v a 2 s.c om * * @param parentInfo info for the parent menu * @param submenu the submenu whose parent view should be obtained * @return the parent view, or {@code null} if one could not be found */ @Nullable private View findParentViewForSubmenu(@NonNull CascadingMenuInfo parentInfo, @NonNull MenuBuilder submenu) { final MenuItem owner = findMenuItemForSubmenu(parentInfo.menu, submenu); if (owner == null) { // Couldn't find the submenu owner. return null; } // The adapter may be wrapped. Adjust the index if necessary. final int headersCount; final MenuAdapter menuAdapter; final ListView listView = parentInfo.getListView(); final ListAdapter listAdapter = listView.getAdapter(); if (listAdapter instanceof HeaderViewListAdapter) { final HeaderViewListAdapter headerAdapter = (HeaderViewListAdapter) listAdapter; headersCount = headerAdapter.getHeadersCount(); menuAdapter = (MenuAdapter) headerAdapter.getWrappedAdapter(); } else { headersCount = 0; menuAdapter = (MenuAdapter) listAdapter; } // Find the index within the menu adapter's data set of the menu item. int ownerPosition = AbsListView.INVALID_POSITION; for (int i = 0, count = menuAdapter.getCount(); i < count; i++) { if (owner == menuAdapter.getItem(i)) { ownerPosition = i; break; } } if (ownerPosition == AbsListView.INVALID_POSITION) { // Couldn't find the owner within the menu adapter. return null; } // Adjust the index for the adapter used to display views. ownerPosition += headersCount; // Adjust the index for the visible views. final int ownerViewPosition = ownerPosition - listView.getFirstVisiblePosition(); if (ownerViewPosition < 0 || ownerViewPosition >= listView.getChildCount()) { // Not visible on screen. return null; } return listView.getChildAt(ownerViewPosition); }
From source file:com.tweetlanes.android.view.UserFeedFragment.java
@Override public void onJumpToTop() { if (mUserFeedListView != null) { ListView listView = mUserFeedListView.getRefreshableView(); if (listView != null && listView.getAdapter() != null && listView.getAdapter().isEmpty() == false) { listView.setSelection(0);//from w w w . j a v a2s.co m } } }
From source file:com.shafiq.mytwittle.view.UserFeedFragment.java
@Override public void onJumpToTop() { if (mUserFeedListView != null) { ListView listView = mUserFeedListView.getRefreshableView(); if (listView != null && listView.getAdapter() != null && listView.getAdapter().isEmpty() == false) { listView.setSelection(0);/*from ww w .j a v a 2 s. c o m*/ } } }
From source file:drawnzer.anurag.archivereaddemo.RarFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { // TODO Auto-generated method stub final ListView lsView = (ListView) view.findViewById(R.id.ls); lsView.setSelector(R.drawable.button_click); lsView.setAdapter(new FileAdapter(getActivity(), new File(path).listFiles())); lsView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from ww w .ja v a2 s.c om public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub if (opened) { //zip file already opened.... //we are selecting sub files inside of zip file.... //getting selected entry from list view.... RarObj obj = (RarObj) lsView.getAdapter().getItem(arg2); //getting path of selected folder inside zip archive.... rar_path = obj.getPath(); if (obj.isFile()) { // a files is selected inside of archive.... Toast.makeText(getActivity(), "A file is selected....", Toast.LENGTH_SHORT).show(); } else { //a folder is selected inside zip archive.... //so further listing the selected folder.... try { lsView.setAdapter(read_rar.getAdapter(rar_path, getActivity())); } catch (ZipException e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(getActivity(), "Something went wrong....", Toast.LENGTH_SHORT).show(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(getActivity(), "Something went wrong....", Toast.LENGTH_SHORT).show(); } } return; } //folder or some file is selected.... //getting the file.... File getFile = (File) lsView.getAdapter().getItem(arg2); if (getFile.isDirectory()) { //updating th path.... path = path + "/" + getFile.getName(); //updating the listview as per new path.... lsView.setAdapter(new FileAdapter(getActivity(), new File(path).listFiles())); } else { //file is selected.... if (getFile.getName().endsWith(".rar")) { //open the zip file.... opened = true; read_rar = new ReadArchive(getFile); if (rar_path == null) rar_path = "/"; try { lsView.setAdapter(read_rar.getAdapter(rar_path, getActivity())); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(getActivity(), "Invalid zip file....", Toast.LENGTH_SHORT).show(); } } else Toast.makeText(getActivity(), "Choose a rar file to open....", Toast.LENGTH_SHORT).show(); } } }); lsView.setOnItemLongClickListener(null); }
From source file:drawnzer.anurag.archivereaddemo.ZipFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { // TODO Auto-generated method stub final ListView lsView = (ListView) view.findViewById(R.id.ls); lsView.setSelector(R.drawable.button_click); lsView.setAdapter(new FileAdapter(getActivity(), new File(path).listFiles())); lsView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*from ww w.ja v a 2 s. c o m*/ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub if (opened) { //zip file already opened.... //we are selecting sub files inside of zip file.... //getting selected entry from list view.... ZipObj obj = (ZipObj) lsView.getAdapter().getItem(arg2); //getting path of selected folder inside zip archive.... zip_path = obj.getPath(); if (obj.isFile()) { // a files is selected inside of archive.... Toast.makeText(getActivity(), "A file is selected....", Toast.LENGTH_SHORT).show(); } else { //a folder is selected inside zip archive.... //so further listing the selected folder.... try { lsView.setAdapter(read_zip.getAdapter(zip_path, getActivity())); } catch (ZipException e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(getActivity(), "Something went wrong....", Toast.LENGTH_SHORT).show(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(getActivity(), "Something went wrong....", Toast.LENGTH_SHORT).show(); } } return; } //folder or some file is selected.... //getting the file.... File getFile = (File) lsView.getAdapter().getItem(arg2); if (getFile.isDirectory()) { //updating th path.... path = path + "/" + getFile.getName(); //updating the listview as per new path.... lsView.setAdapter(new FileAdapter(getActivity(), new File(path).listFiles())); } else { //file is selected.... if (getFile.getName().endsWith(".zip")) { //open the zip file.... opened = true; read_zip = new ReadArchive(getFile); if (zip_path == null) zip_path = "/"; try { lsView.setAdapter(read_zip.getAdapter(zip_path, getActivity())); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(getActivity(), "Invalid zip file....", Toast.LENGTH_SHORT).show(); } } else Toast.makeText(getActivity(), "Choose a zip file to open....", Toast.LENGTH_SHORT).show(); } } }); lsView.setOnItemLongClickListener(null); }
From source file:drawnzer.anurag.archivereaddemo.TarFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { // TODO Auto-generated method stub final ListView lsView = (ListView) view.findViewById(R.id.ls); lsView.setSelector(R.drawable.button_click); lsView.setAdapter(new FileAdapter(getActivity(), new File(path).listFiles())); lsView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from ww w .j av a 2 s . c o m public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub if (opened) { //zip file already opened.... //we are selecting sub files inside of zip file.... //getting selected entry from list view.... TarObj obj = (TarObj) lsView.getAdapter().getItem(arg2); //getting path of selected folder inside zip archive.... tar_path = obj.getPath(); if (obj.isFile()) { // a files is selected inside of archive.... Toast.makeText(getActivity(), "A file is selected....", Toast.LENGTH_SHORT).show(); } else { //a folder is selected inside zip archive.... //so further listing the selected folder.... if (tar_path.startsWith("/")) tar_path = tar_path.substring(1, tar_path.length()); try { lsView.setAdapter(read_tar.getAdapter(tar_path, getActivity())); } catch (ZipException e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(getActivity(), "Something went wrong....", Toast.LENGTH_SHORT).show(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(getActivity(), "Something went wrong....", Toast.LENGTH_SHORT).show(); } } return; } //folder or some file is selected.... //getting the file.... File getFile = (File) lsView.getAdapter().getItem(arg2); if (getFile.isDirectory()) { //updating th path.... path = path + "/" + getFile.getName(); //updating the listview as per new path.... lsView.setAdapter(new FileAdapter(getActivity(), new File(path).listFiles())); } else { //file is selected.... if (getFile.getName().endsWith(".tar") || getFile.getName().endsWith(".tar.bz2")) { //open the zip file.... opened = true; read_tar = new ReadArchive(getFile); if (tar_path == null) tar_path = "/"; try { lsView.setAdapter(read_tar.getAdapter(tar_path, getActivity())); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(getActivity(), "Invalid tar file....", Toast.LENGTH_SHORT).show(); } } else Toast.makeText(getActivity(), "Choose a tar file to open....", Toast.LENGTH_SHORT).show(); } } }); lsView.setOnItemLongClickListener(null); }
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;// w ww . j ava2s . c o 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.audiokernel.euphonyrmt.fragments.QueueFragment.java
@Override public void onListItemClick(final ListView l, final View v, final int position, final long id) { super.onListItemClick(l, v, position, id); final int song = ((Music) l.getAdapter().getItem(position)).getSongId(); QueueControl.run(QueueControl.SKIP_TO_ID, song); }