List of usage examples for android.widget ListView setMultiChoiceModeListener
public void setMultiChoiceModeListener(MultiChoiceModeListener listener)
From source file:com.btmura.android.reddit.app.ThingListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) v.findViewById(android.R.id.list); lv.setVerticalScrollBarEnabled(false); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); lv.setMultiChoiceModeListener(this); SwipeDismissTouchListener touchListener = new SwipeDismissTouchListener(lv, this); lv.setOnTouchListener(touchListener); ThumbnailLoader.lock(false);// w ww .jav a 2 s .co m final OnScrollListener scrollListener = touchListener.makeScrollListener(); lv.setOnScrollListener(new OnScrollListener() { @Override public void onScroll(AbsListView lv, int firstVisible, int visibleCount, int totalCount) { scrollListener.onScroll(lv, firstVisible, visibleCount, totalCount); ThingListFragment.this.onScroll(lv, firstVisible, visibleCount, totalCount); } @Override public void onScrollStateChanged(AbsListView lv, int scrollState) { scrollListener.onScrollStateChanged(lv, scrollState); ThingListFragment.this.onScrollStateChanged(lv, scrollState); } }); return v; }
From source file:com.jhk.whysoformal.activity.musiclist.fragment.MusicListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); ListView listView = (ListView) view.findViewById(android.R.id.list); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override/*from w w w.ja va 2s . c o m*/ public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { return true; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { } }); return view; }
From source file:cat.wuyingren.rorhelper.fragments.GameListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); dataSource = new GameDataSource(getActivity()); dataSource.open();// ww w . j a va 2s.c o m values = dataSource.getAllGames(); adapter = new MultipleRowAdapter(getActivity(), values); setListAdapter(adapter); final ListView listView = getListView(); listView.setItemsCanFocus(false); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new ListView.MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { // Here you can do something when items are selected/de-selected, // such as update the title in the CAB //mode.setTag(); int selectionColor = getResources().getColor(R.color.colorPrimary); Log.w("TAG", "onItemCheckedStateChanged() " + checked + " " + position); mode.setSubtitle(listView.getCheckedItemCount() + " selected"); if (checked) { listView.getChildAt(position).setBackgroundColor(selectionColor); } else { listView.getChildAt(position) .setBackgroundColor(getResources().getColor(android.R.color.transparent)); } } @Override public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) { // Inflate the menu for the CAB Log.w("TAG", "onCreateActionMode"); MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.menu_context, menu); mode.setTitle(getString(R.string.action_choose)); return true; } @Override public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) { // Here you can perform updates to the CAB due to // an invalidate() request return false; } @Override public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) { // Respond to clicks on the actions in the CAB switch (item.getItemId()) { case R.id.action_delete: deleteItems(listView.getCheckedItemPositions()); mode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(android.view.ActionMode mode) { // Here you can make any necessary updates to the activity when // the CAB is removed. By default, selected items are deselected/unchecked. SparseBooleanArray checked = listView.getCheckedItemPositions(); for (int i = 0; i < listView.getAdapter().getCount(); i++) { if (checked.get(i)) { listView.getChildAt(i) .setBackgroundColor(getResources().getColor(android.R.color.transparent)); } } } }); // dataSource.close(); }
From source file:net.lacolaco.smileessence.activity.EditTemplateActivity.java
private void initializeViews() { ListView listView = getListView(); adapter = new CustomListAdapter<>(this, Template.class); listView.setAdapter(adapter);/*from w ww .j a v a 2s . com*/ adapter.addToTop(getTemplates()); adapter.update(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setOnItemClickListener(this); listView.setMultiChoiceModeListener(this); }
From source file:net.lacolaco.smileessence.activity.EditExtractionActivity.java
private void initializeViews() { ListView listView = getListView(); adapter = new CustomListAdapter<>(this, ExtractionWord.class); listView.setAdapter(adapter);/* w w w.ja v a 2 s . c o m*/ adapter.addToTop(getExtractionWords()); adapter.update(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setOnItemClickListener(this); listView.setMultiChoiceModeListener(this); }
From source file:com.sakisds.icymonitor.activities.ConnectionActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_connection); mSettings = getSharedPreferences(MainViewActivity.SHAREDPREFS_FILE, 0); refreshListAdapter();/*from w w w . j a va2s .c o m*/ ListView listView = getListView(); listView.setLongClickable(true); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new MultipleChoiceListener()); getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { String url = "http://" + ((TextView) v.findViewById(R.id.text_address)).getText().toString(); connect(url); } }); // Http Client mClient.setMaxRetriesAndTimeout(2, 2000); // Setup GCM context = getApplicationContext(); regid = getRegistrationId(context); if (regid.length() == 0) { registerBackground(); } gcm = GoogleCloudMessaging.getInstance(this); }
From source file:net.named_data.nfd.FaceListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @SuppressLint("InflateParams") View v = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_face_list_list_header, null); getListView().addHeaderView(v, null, false); getListView().setDivider(getResources().getDrawable(R.drawable.list_item_divider)); // Get info unavailable view m_faceListInfoUnavailableView = v.findViewById(R.id.face_list_info_unavailable); // Get progress bar spinner view m_reloadingListProgressBar = (ProgressBar) v.findViewById(R.id.face_list_reloading_list_progress_bar); // Setup list view for deletion ListView listView = getListView(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override//from w w w . ja v a 2s. c o m public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked && id < 256) { getListView().setItemChecked(position, false); return; } if (checked) m_facesToDelete.add((int) id); else m_facesToDelete.remove((int) id); } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater menuInflater = mode.getMenuInflater(); menuInflater.inflate(R.menu.menu_face_list_multiple_modal_menu, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_delete_face_item: G.Log("Requesting to delete " + String.valueOf(m_facesToDelete)); // Delete selected faceIds m_faceDestroyAsyncTask = new FaceDestroyAsyncTask(); m_faceDestroyAsyncTask.execute(m_facesToDelete); m_facesToDelete = new HashSet<>(); mode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode mode) { } private HashSet<Integer> m_facesToDelete = new HashSet<>(); }); }
From source file:com.btmura.android.reddit.app.NavigationFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) v.findViewById(android.R.id.list); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); lv.setMultiChoiceModeListener(this); return v;/*from w ww .j a v a 2 s . c o m*/ }
From source file:no.digipost.android.gui.content.UploadActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((DigipostApplication) getApplication()).getTracker(DigipostApplication.TrackerName.APP_TRACKER); setContentView(R.layout.activity_upload); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);// w w w.j ava 2s .co m getSupportActionBar().setTitle(R.string.upload); getSupportActionBar().setHomeButtonEnabled(true); absolutePath = (TextView) findViewById(R.id.upload_file_path); availableSpace = (TextProgressBar) findViewById(R.id.upload_available_space); listEmpty = (TextView) findViewById(R.id.upload_list_empty); mDirectory = DEFAULT_INITIAL_DIRECTORY; mFiles = new ArrayList<File>(); ListView listView = (ListView) findViewById(R.id.upload_file_list); listView.setEmptyView(listEmpty); listView.setOnItemClickListener(new ListOnItemClickListener()); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setFastScrollEnabled(true); listView.setMultiChoiceModeListener(new UploadMultiChoiceModeListener()); listAdapter = new UploadListAdapter(this, mFiles); listView.setAdapter(listAdapter); content = getIntent().getIntExtra(ApiConstants.UPLOAD, ApplicationConstants.MAILBOX); Permissions.requestWritePermissionsIfMissing(getApplicationContext(), UploadActivity.this); executeSetAccountInfoTask(); }
From source file:com.github.jvanhie.discogsscrobbler.NowPlayingFragment.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setSelection(final ListView list) { list.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); list.setSelector(R.drawable.track_selector); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from w w w.j a v a2s. c om public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (mBound) { //fully stop previous playlist since we start again from the beginning of the selected track ArrayList<Track> trackList = new ArrayList<Track>(mService.trackList); mService.stop(); mService.trackList = trackList; mService.currentTrack = i; mService.resume(); } } }); list.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode actionMode, int i, long l, boolean b) { } @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.now_playing_cab, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { SparseBooleanArray checkedItems = list.getCheckedItemPositions(); final List<Integer> positions = new ArrayList<Integer>(); if (checkedItems != null) { for (int i = 0; i < checkedItems.size(); i++) { if (checkedItems.valueAt(i)) { positions.add(checkedItems.keyAt(i)); } } } switch (menuItem.getItemId()) { case R.id.play_selection: if (mBound) { //change tracklist and start over again ArrayList<Track> newTrackList = new ArrayList<Track>(); for (Integer i : positions) { newTrackList.add(mService.trackList.get(i)); } //fully stop previous playlist since we start again from the beginning mService.stop(); mService.trackList = newTrackList; mService.currentTrack = 0; mService.resume(); } actionMode.finish(); break; case R.id.remove_selection: int currPlaying = mService.currentTrack; int newPlaying = -1; //change tracklist and start over again ArrayList<Track> newTrackList = new ArrayList<Track>(); for (int i = 0; i < mService.trackList.size(); i++) { if (!positions.contains(i)) { newTrackList.add(mService.trackList.get(i)); } //calculate new currently playing counter if (i == currPlaying) { if (positions.contains(i)) { currPlaying++; } else { newPlaying = newTrackList.size() - 1; } } } //the currently playing track was removed, start fresh from the next available if (currPlaying != mService.currentTrack) { mService.stop(); if (newPlaying != -1) { mService.trackList = newTrackList; mService.currentTrack = newPlaying; mService.resume(); } } else { //pause the playlist and resume with the new tracklist mService.pause(); mService.trackList = newTrackList; mService.currentTrack = newPlaying; mService.resume(); } actionMode.finish(); break; } return false; } @Override public void onDestroyActionMode(ActionMode actionMode) { } }); }