List of usage examples for android.widget ListView setChoiceMode
public void setChoiceMode(int choiceMode)
From source file:ni.org.ics.zikapositivas.appmovil.wizard.ui.MultipleChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); ((TextView) rootView.findViewById(R.id.label_hint)).setText(mPage.getHint()); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_multiple_choice, android.R.id.text1, mChoices)); listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE); // Pre-select currently selected items. new Handler().post(new Runnable() { @Override/* w ww .j av a 2 s .c om*/ public void run() { ArrayList<String> selectedItems = mPage.getData().getStringArrayList(Page.SIMPLE_DATA_KEY); if (selectedItems == null || selectedItems.size() == 0) { return; } Set<String> selectedSet = new HashSet<String>(selectedItems); for (int i = 0; i < mChoices.size(); i++) { if (selectedSet.contains(mChoices.get(i))) { listView.setItemChecked(i, true); } } } }); return rootView; }
From source file:com.pentapus.pentapusdmh.Fragments.EncounterPrep.AddMonster.WizardMonsterEdit.DmgVulFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_page_dmgvul, container, false); ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_multiple_choice, android.R.id.text1, mChoices)); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // Pre-select currently selected items. new Handler().post(new Runnable() { @Override/*from www . jav a 2s.c om*/ public void run() { ArrayList<String> selectedItems = mPage.getData().getStringArrayList(mKey); if (selectedItems == null || selectedItems.size() == 0) { return; } Set<String> selectedSet = new HashSet<String>(selectedItems); for (int i = 0; i < mChoices.size(); i++) { if (selectedSet.contains(mChoices.get(i))) { selections.add(mChoices.get(i)); listView.setItemChecked(i, true); } } mPage.getData().putStringArrayList(Page.SIMPLE_DATA_KEY, selections); mPage.notifyDataChanged(); } }); return rootView; }
From source file:ni.org.ics.estudios.appmovil.wizard.ui.MultipleChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); mTitleTextInput = (TextView) rootView.findViewById(android.R.id.title); mTitleTextInput.setText(mPage.getTitle()); mTitleTextInput.setTextColor(Color.parseColor(mPage.getTextColor())); mHintTextInput = (TextView) rootView.findViewById(R.id.label_hint); mHintTextInput.setText(mPage.getHint()); mHintTextInput.setTextColor(Color.parseColor(mPage.getmHintTextColor())); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_multiple_choice, android.R.id.text1, mChoices)); listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE); // Pre-select currently selected items. new Handler().post(new Runnable() { @Override//ww w . j a v a 2 s . c o m public void run() { ArrayList<String> selectedItems = mPage.getData().getStringArrayList(Page.SIMPLE_DATA_KEY); if (selectedItems == null || selectedItems.size() == 0) { return; } Set<String> selectedSet = new HashSet<String>(selectedItems); for (int i = 0; i < mChoices.size(); i++) { if (selectedSet.contains(mChoices.get(i))) { listView.setItemChecked(i, true); } } } }); return rootView; }
From source file:de.bennir.DVBViewerController.wizard.ui.MultipleChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); String title = null;//from ww w. ja v a 2 s .c om try { title = getString(getResources().getIdentifier(mKey, "string", "de.bennir.DVBViewerController")); } catch (Exception e) { e.printStackTrace(); } if (title == null) ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); else ((TextView) rootView.findViewById(android.R.id.title)).setText(title); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_multiple_choice, android.R.id.text1, mChoices)); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // Pre-select currently selected items. new Handler().post(new Runnable() { @Override public void run() { ArrayList<String> selectedItems = mPage.getData().getStringArrayList(Page.SIMPLE_DATA_KEY); if (selectedItems == null || selectedItems.size() == 0) { return; } Set<String> selectedSet = new HashSet<String>(selectedItems); for (int i = 0; i < mChoices.size(); i++) { if (selectedSet.contains(mChoices.get(i))) { listView.setItemChecked(i, true); } } } }); return rootView; }
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 w w.j a va2 s. c om*/ adapter.addToTop(getTemplates()); adapter.update(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setOnItemClickListener(this); listView.setMultiChoiceModeListener(this); }
From source file:com.brookmanholmes.bma.wizard.ui.ReviewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { wizardModel = callbacks.onGetModel(); wizardModel.registerListener(this); onPageTreeChanged();/*from w w w. ja v a 2s . com*/ View rootView = inflater.inflate(R.layout.fragment_page, container, false); TextView titleView = (TextView) rootView.findViewById(android.R.id.title); titleView.setText(R.string.title_review); titleView.setTextColor(ContextCompat.getColor(getContext(), R.color.colorAccent)); ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(reviewAdapter); listView.setDividerHeight(0); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); return rootView; }
From source file:com.wizard.ui.SingleChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new ArrayAdapter<String>(getActivity(), //android.R.layout.simple_list_item_single_choice, R.layout.mylist, android.R.id.text1, mChoices)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // Pre-select currently selected item. new Handler().post(new Runnable() { @Override//from w ww . j a v a2 s.c o m public void run() { String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY); for (int i = 0; i < mChoices.size(); i++) { if (mChoices.get(i).equals(selection)) { listView.setItemChecked(i, true); break; } } } }); return rootView; }
From source file:com.androidquery.simplefeed.activity.FriendsActivity.java
private void initView() { friends = new FriendsAdapter(); aq.id(R.id.list);// ww w. j a va2 s. c o m aq.adapter(friends).scrolledBottom(this, "scrolledBottom").itemClicked(this, "itemClicked"); ListView lv = aq.getListView(); lv.setItemsCanFocus(false); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); ajaxFriends(0); aq.id(R.id.edit_input).textChanged(this, "searchChanged"); if (selectable) { aq.id(R.id.done_box).visible(); aq.id(R.id.button_done).clicked(this, "doneClicked"); } }
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();/*w w w . ja v a 2s. c om*/ 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.EditExtractionActivity.java
private void initializeViews() { ListView listView = getListView(); adapter = new CustomListAdapter<>(this, ExtractionWord.class); listView.setAdapter(adapter);//from w w w . ja v a 2 s . co m adapter.addToTop(getExtractionWords()); adapter.update(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setOnItemClickListener(this); listView.setMultiChoiceModeListener(this); }