List of usage examples for android.widget ListView setChoiceMode
public void setChoiceMode(int choiceMode)
From source file:com.example.android.wizardpager.wizard.ui.dataorbs.SingleChoiceFragmentWithDataOrbs.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 DataOrbAdapter(getActivity(), 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 .co 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).displayString.equals(selection)) { listView.setItemChecked(i, true); break; } } } }); return rootView; }
From source file:org.fdroid.fdroid.views.fragments.SelectLocalAppsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setEmptyText(getString(R.string.no_applications_found)); packageManager = getActivity().getPackageManager(); defaultAppIcon = getActivity().getResources().getDrawable(android.R.drawable.sym_def_app_icon); selectLocalAppsActivity = (SelectLocalAppsActivity) getActivity(); ListView listView = getListView(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.select_local_apps_list_item, null,/* w ww. j a va 2 s . co m*/ new String[] { InstalledAppProvider.DataColumns.APPLICATION_LABEL, InstalledAppProvider.DataColumns.APP_ID, }, new int[] { R.id.application_label, R.id.package_name, }, 0); adapter.setViewBinder(new ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (columnIndex == cursor.getColumnIndex(InstalledAppProvider.DataColumns.APP_ID)) { String packageName = cursor.getString(columnIndex); TextView textView = (TextView) view.findViewById(R.id.package_name); textView.setText(packageName); LinearLayout ll = (LinearLayout) view.getParent().getParent(); ImageView iconView = (ImageView) ll.getChildAt(0); Drawable icon; try { icon = packageManager.getApplicationIcon(packageName); } catch (PackageManager.NameNotFoundException e) { icon = defaultAppIcon; } iconView.setImageDrawable(icon); return true; } return false; } }); setListAdapter(adapter); setListShown(false); // start out with a progress indicator // either reconnect with an existing loader or start a new one getLoaderManager().initLoader(0, null, this); // build list of existing apps from what is on the file system if (FDroidApp.selectedApps == null) { Set<String> selectedApps = new HashSet<>(); for (String filename : LocalRepoManager.get(selectLocalAppsActivity).repoDir.list()) { if (filename.matches(".*\\.apk")) { String packageName = filename.substring(0, filename.indexOf("_")); selectedApps.add(packageName); } } FDroidApp.selectedApps = selectedApps; } }
From source file:com.roque.rueda.cashflows.fragments.AccountListFragment.java
/** * Set the listeners for this ListView./*from w ww. j a v a2 s . c o m*/ */ private void setListerners() { ListView lv = getListView(); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); lv.setDivider(getResources().getDrawable(R.color.divider_blue)); lv.setDividerHeight(1); }
From source file:com.btmura.android.reddit.app.CommentListFragment.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); lv.setDivider(null);/*from www . ja v a 2s . c om*/ return v; }
From source file:net.i2p.android.wizard.ui.ReviewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_wizard_page, container, false); TextView titleView = (TextView) rootView.findViewById(android.R.id.title); titleView.setText(R.string.review);/*ww w .j ava 2s . c om*/ titleView.setTextColor(getResources().getColor(R.color.review_green)); ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(mReviewAdapter); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); return rootView; }
From source file:org.ohmage.prompt.multichoice.MultiChoicePrompt.java
@Override public View getView(Context context) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); ListView listView = (ListView) inflater.inflate(R.layout.prompt_multi_choice, null); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); String[] from = new String[] { "value" }; int[] to = new int[] { android.R.id.text1 }; List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < mChoices.size(); i++) { HashMap<String, String> map = new HashMap<String, String>(); map.put("key", mChoices.get(i).key); map.put("value", mChoices.get(i).label); data.add(map);//from w w w . jav a2 s . com } SimpleAdapter adapter = new SimpleAdapter(context, data, R.layout.multi_choice_list_item, from, to); adapter.setViewBinder(new ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { ((CheckedTextView) view).setText((String) data); return true; } }); listView.setAdapter(adapter); if (mSelectedIndexes.size() > 0) { for (int index : mSelectedIndexes) { if (index >= 0 && index < mChoices.size()) listView.setItemChecked(index, true); } } listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //SparseBooleanArray checkItemPositions = ((ListView)parent).getCheckedItemPositions(); if (((ListView) parent).isItemChecked(position)) { mSelectedIndexes.add(Integer.valueOf(position)); } else { mSelectedIndexes.remove(Integer.valueOf(position)); } } }); return listView; }
From source file:br.com.hojeti.wizardpager.ui.ReviewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); TextView titleView = (TextView) rootView.findViewById(android.R.id.title); titleView.setText(R.string.review);//from w w w. jav a 2 s.c om titleView.setTextColor(getResources().getColor(R.color.review_green)); ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(mReviewAdapter); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); return rootView; }
From source file:com.wab.lernapp.wizard.ui.ReviewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); TextView titleView = (TextView) rootView.findViewById(android.R.id.title); titleView.setText(R.string.review);/*from ww w . ja va 2s . c o m*/ ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(mReviewAdapter); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); return rootView; }
From source file:org.kanbansalad.scanner.client.android.scan.ScanFragment.java
private void enableContextActionBarWhenSelectingScannedItems(ListView scannedTagsView) { scannedTagsView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); scannedTagsView.setOnItemClickListener(new ItemSelectedListener()); }
From source file:com.djkim.slap.selectionModel.ReviewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); TextView titleView = (TextView) rootView.findViewById(android.R.id.title); titleView.setText(R.string.review);//from w w w .ja va 2 s. c o m titleView.setTextColor(getResources().getColor(R.color.step_pager_selected_tab_color)); ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(mReviewAdapter); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); return rootView; }