List of usage examples for android.widget AbsListView CHOICE_MODE_SINGLE
int CHOICE_MODE_SINGLE
To view the source code for android.widget AbsListView CHOICE_MODE_SINGLE.
Click Source Link
From source file:com.irontec.mintzatu.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); BugSenseHandler.initAndStartSession(getApplicationContext(), "6e0ba9cd"); setContentView(R.layout.activity_main); title = new String[] { "Lekuak", "Lagunak", "Esploratu", "Profila", "Ezarpenak" }; // subtitle = new String[] { "Subtitle Fragment 1", "Subtitle Fragment 2", // "Subtitle Fragment 3" }; icon = new int[] { R.drawable.lekuak, R.drawable.lagunak, R.drawable.esploratu, R.drawable.profila, R.drawable.ezarpenak };/*www . ja v a 2 s .co m*/ mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerList.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mMenuAdapter = new MenuListAdapter(this, title, icon); mDrawerList.setAdapter(mMenuAdapter); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { public void onDrawerClosed(View view) { super.onDrawerClosed(view); } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
From source file:org.lunci.dumbthing.dialog.CalendarDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.calendar_layout, container); CalendarPickerView calendar = (CalendarPickerView) view.findViewById(R.id.calendar); if (mDates != null && mDates.size() > 0) { final Date minDate = mDates.get(0); final Date maxDate = new Date(System.currentTimeMillis() + 86400000);//add one more day calendar.init(minDate, maxDate); calendar.highlightDates(mDates); calendar.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); calendar.setOnDateSelectedListener(new CalendarPickerView.OnDateSelectedListener() { @Override/*from ww w . j av a 2 s . c o m*/ public void onDateSelected(Date date) { EventBus.getDefault().post(new CalendarDialogCallbacks(date)); dismiss(); } @Override public void onDateUnselected(Date date) { } }); } else { this.dismiss(); } return view; }
From source file:ni.org.ics.estudios.appmovil.wizard.ui.SingleChoiceFragment.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()); if (!mPage.ismEnabled()) { mTitleTextInput.setTextColor(Color.GRAY); } else {//from ww w .j a va 2 s .c o m 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_single_choice, android.R.id.text1, mChoices)); listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); listView.setEnabled(mPage.ismEnabled()); // Pre-select currently selected item. new Handler().post(new Runnable() { @Override 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:cn.wjh1119.bestnews.ui.fragment.ListItemChoiceManager.java
public void onClick(RecyclerView.ViewHolder vh) { if (mChoiceMode == AbsListView.CHOICE_MODE_NONE) return;/*from w ww .j a va 2 s . c o m*/ int checkedItemCount = mCheckStates.size(); int position = vh.getAdapterPosition(); if (position == RecyclerView.NO_POSITION) { Logger.d(LOG_TAG, "Unable to Set Item State"); return; } switch (mChoiceMode) { case AbsListView.CHOICE_MODE_NONE: break; case AbsListView.CHOICE_MODE_SINGLE: { boolean checked = mCheckStates.get(position, false); if (!checked) { for (int i = 0; i < checkedItemCount; i++) { mAdapter.notifyItemChanged(mCheckStates.keyAt(i)); } mCheckStates.clear(); mCheckStates.put(position, true); mCheckedIdStates.clear(); mCheckedIdStates.put(mAdapter.getItemId(position), position); } // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE: { boolean checked = mCheckStates.get(position, false); mCheckStates.put(position, !checked); // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: { throw new RuntimeException("Multiple Modal not implemented in ListItemChoiceManager."); } } }
From source file:app.com.example.android.sunshine.ItemChoiceManager.java
public void onClick(RecyclerView.ViewHolder vh) { if (mChoiceMode == AbsListView.CHOICE_MODE_NONE) return;/*from www . java2s .c om*/ int checkedItemCount = mCheckStates.size(); int position = vh.getAdapterPosition(); if (position == RecyclerView.NO_POSITION) { Log.d(LOG_TAG, "Unable to Set Item State"); return; } switch (mChoiceMode) { case AbsListView.CHOICE_MODE_NONE: break; case AbsListView.CHOICE_MODE_SINGLE: { boolean checked = mCheckStates.get(position, false); if (!checked) { for (int i = 0; i < checkedItemCount; i++) { mAdapter.notifyItemChanged(mCheckStates.keyAt(i)); } mCheckStates.clear(); mCheckStates.put(position, true); mCheckedIdStates.clear(); mCheckedIdStates.put(mAdapter.getItemId(position), position); } // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE: { boolean checked = mCheckStates.get(position, false); mCheckStates.put(position, !checked); // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: { throw new RuntimeException("Multiple Modal not implemented in ItemChoiceManager."); } } }
From source file:com.justinbull.ichnaeachecker.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//w w w .j av a2s.co m setCellInfo(); mCellListView = (ListView) findViewById(R.id.cellListView); mCellListView.setAdapter(mCellListAdapter); mCellListView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); mCellListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { GeneralCellInfo cell = (GeneralCellInfo) parent.getItemAtPosition(position); if (!cell.isFullyKnown()) { Snackbar snack = Snackbar.make(view, "Not enough information known about selected cell", Snackbar.LENGTH_SHORT); snack.getView() .setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorError)); snack.show(); return; } mSelectedCell = cell; view.setSelected(true); Snackbar.make(view, "Selected " + mSelectedCell.getCellType() + " Cell " + mSelectedCell.getFriendlyCellIdentity(), Snackbar.LENGTH_SHORT).show(); } }); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); assert fab != null; fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { if (ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) { setCellInfo(); } if (mSelectedCell == null) { Toast.makeText(MainActivity.this, "Choose a cell to check", Toast.LENGTH_SHORT).show(); return; } final Snackbar snack = Snackbar.make(view, "Checking Mozilla Location Services database...", Snackbar.LENGTH_INDEFINITE); snack.show(); try { final RequestHandle handler = getIchnaeaLookup(snack); assert handler != null; snack.setAction("CANCEL", new View.OnClickListener() { @Override public void onClick(View view) { snack.setText("Cancelling lookup request..."); if (!handler.isFinished()) { handler.cancel(true); } else { snack.setText("Request already finished!"); snack.setDuration(Snackbar.LENGTH_LONG); snack.show(); } } }).show(); } catch (IllegalArgumentException e) { Log.w(TAG, "onClick: ", e); snack.setDuration(Snackbar.LENGTH_SHORT); snack.setText("Not enough information known about selected cell"); snack.show(); } } }); }
From source file:fragments.ExampleDraggableListViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try {/*from w w w.j a va 2 s .co m*/ View activity_list_view = inflater.inflate(R.layout.draggable_list_test, container, false); ArrayList<HasItsOwnView> listToDisplay = new ArrayList<HasItsOwnView>(); addItem(listToDisplay, "A1"); addItem(listToDisplay, "B1"); addItem(listToDisplay, "C1"); addItem(listToDisplay, "A2"); addItem(listToDisplay, "B2"); addItem(listToDisplay, "C2"); addItem(listToDisplay, "A3"); addItem(listToDisplay, "B3"); addItem(listToDisplay, "C3"); addItem(listToDisplay, "A4"); addItem(listToDisplay, "B4"); addItem(listToDisplay, "C4"); addItem(listToDisplay, "A5"); addItem(listToDisplay, "B5"); addItem(listToDisplay, "C5"); addItem(listToDisplay, "A6"); addItem(listToDisplay, "B6"); addItem(listToDisplay, "C6"); addItem(listToDisplay, "A7"); addItem(listToDisplay, "B7"); addItem(listToDisplay, "C7"); addItem(listToDisplay, "A8"); addItem(listToDisplay, "B8"); addItem(listToDisplay, "C8"); SimpleBaseAdapter adapter = new SimpleBaseAdapter(getActivity(), listToDisplay); DraggableListView listView = (DraggableListView) activity_list_view.findViewById(R.id.dynamic_listview); listView.setModelModificationListener(new ListModificationListener(listToDisplay)); listView.setAdapter(adapter); listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); return activity_list_view; } catch (Exception e) { e.printStackTrace(); } return super.onCreateView(inflater, container, savedInstanceState); }
From source file:com.example.radioplayer.adapter.ItemChoiceManager.java
public void onClick(RecyclerView.ViewHolder vh) { if (mChoiceMode == AbsListView.CHOICE_MODE_NONE) { return;//from w w w . ja va 2s .c om } int checkedItemCount = mCheckStates.size(); int position = vh.getAdapterPosition(); if (position == RecyclerView.NO_POSITION) { Log.d(LOG_TAG, "Unable to Set Item State"); return; } switch (mChoiceMode) { case AbsListView.CHOICE_MODE_NONE: break; case AbsListView.CHOICE_MODE_SINGLE: { boolean checked = mCheckStates.get(position, false); if (!checked) { for (int i = 0; i < checkedItemCount; i++) { mAdapter.notifyItemChanged(mCheckStates.keyAt(i)); } mCheckStates.clear(); mCheckStates.put(position, true); mCheckedIdStates.clear(); mCheckedIdStates.put(mAdapter.getItemId(position), position); } // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE: { boolean checked = mCheckStates.get(position, false); mCheckStates.put(position, !checked); // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: { throw new RuntimeException("Multiple Modal not implemented in ItemChoiceManager."); } } }
From source file:com.hangulo.xyzreader2.ui.ItemChoiceManager.java
public void onClick(RecyclerView.ViewHolder vh) { if (mChoiceMode == AbsListView.CHOICE_MODE_NONE) return;/* ww w. ja va2 s .com*/ int checkedItemCount = mCheckStates.size(); int position = vh.getAdapterPosition(); if (position == RecyclerView.NO_POSITION) { Log.d(LOG_TAG, "Unable to Set Item State"); return; } switch (mChoiceMode) { case AbsListView.CHOICE_MODE_NONE: break; case AbsListView.CHOICE_MODE_SINGLE: { boolean checked = mCheckStates.get(position, false); if (!checked) { // for (int i = 0; i < checkedItemCount; i++) { // mAdapter.notifyItemChanged(mCheckStates.keyAt(i)); // this original code is occured some UI delay problem, so I've changed to notifyDataSetChanged(). // } mCheckStates.clear(); mCheckStates.put(position, true); mCheckedIdStates.clear(); mCheckedIdStates.put(mAdapter.getItemId(position), position); mAdapter.notifyDataSetChanged(); // select & unselect } // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE: { boolean checked = mCheckStates.get(position, false); mCheckStates.put(position, !checked); // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: { throw new RuntimeException("Multiple Modal not implemented in ItemChoiceManager."); } } }
From source file:com.myapps.xyzreader.ui.ItemChoiceManager.java
public void onClick(RecyclerView.ViewHolder vh) { if (mChoiceMode == AbsListView.CHOICE_MODE_NONE) return;//from www.j a va 2s . co m int checkedItemCount = mCheckStates.size(); int position = vh.getAdapterPosition(); if (position == RecyclerView.NO_POSITION) { Log.d(LOG_TAG, "Unable to Set Item State"); return; } switch (mChoiceMode) { case AbsListView.CHOICE_MODE_NONE: break; case AbsListView.CHOICE_MODE_SINGLE: { boolean checked = mCheckStates.get(position, false); if (!checked) { mCheckStates.clear(); mCheckStates.put(position, true); mCheckedIdStates.clear(); mCheckedIdStates.put(mAdapter.getItemId(position), position); mAdapter.notifyDataSetChanged(); // select & unselect } // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE: { boolean checked = mCheckStates.get(position, false); mCheckStates.put(position, !checked); // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: { throw new RuntimeException("Multiple Modal not implemented in ItemChoiceManager."); } } }