本文整理了Java中android.widget.ListView.getCheckedItemPositions()
方法的一些代码示例,展示了ListView.getCheckedItemPositions()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ListView.getCheckedItemPositions()
方法的具体详情如下:
包路径:android.widget.ListView
类名称:ListView
方法名:getCheckedItemPositions
暂无
代码示例来源:origin: k9mail/k-9
@Override
public boolean retain() {
if (mDialog != null) {
// Save the selection state of each list item
mSelection = mDialog.getListView().getCheckedItemPositions();
mDialog.dismiss();
mDialog = null;
return true;
}
return false;
}
代码示例来源:origin: k9mail/k-9
@Override
public void onClick(DialogInterface dialog, int which) {
ListView listView = ((AlertDialog) dialog).getListView();
SparseBooleanArray pos = listView.getCheckedItemPositions();
boolean includeGlobals = mImportContents.globalSettings && pos.get(0);
List<String> accountUuids = new ArrayList<>();
int start = mImportContents.globalSettings ? 1 : 0;
for (int i = start, end = listView.getCount(); i < end; i++) {
if (pos.get(i)) {
accountUuids.add(mImportContents.accounts.get(i - start).uuid);
}
}
/*
* TODO: Think some more about this. Overwriting could change the store
* type. This requires some additional code in order to work smoothly
* while the app is running.
*/
boolean overwrite = false;
dialog.dismiss();
activity.setNonConfigurationInstance(null);
ImportAsyncTask importAsyncTask = new ImportAsyncTask(activity,
includeGlobals, accountUuids, overwrite, mUri);
activity.setNonConfigurationInstance(importAsyncTask);
importAsyncTask.execute();
}
});
代码示例来源:origin: commonsguy/cw-omnibus
public boolean performActions(MenuItem item) {
SparseBooleanArray checked=getListView().getCheckedItemPositions();
switch (item.getItemId()) {
case R.id.cap:
for (int i=0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
int position=checked.keyAt(i);
String word=words.get(position);
word=word.toUpperCase(Locale.ENGLISH);
adapter.remove(words.get(position));
adapter.insert(word, position);
}
}
return(true);
case R.id.remove:
ArrayList<Integer> positions=new ArrayList<Integer>();
for (int i=0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
positions.add(checked.keyAt(i));
}
}
Collections.sort(positions, Collections.reverseOrder());
for (int position : positions) {
adapter.remove(words.get(position));
}
getListView().clearChoices();
return(true);
}
return(false);
}
代码示例来源:origin: commonsguy/cw-omnibus
public boolean performActions(MenuItem item) {
@SuppressWarnings("unchecked")
ArrayAdapter<String> adapter=(ArrayAdapter<String>)getListAdapter();
SparseBooleanArray checked=getListView().getCheckedItemPositions();
代码示例来源:origin: robolectric/robolectric
@Test
public void givenChoiceModeIsSingleAndMultipleItemsAreChecked_whenGettingCheckedItemPositions_thenReturnOnlyTheLastCheckedPosition() {
prepareListAdapter().withChoiceMode(ListView.CHOICE_MODE_SINGLE).withAnyItemsChecked();
assertThat(listView.getCheckedItemPositions().get(lastCheckedPosition)).isTrue();
assertThat(listView.getCheckedItemCount()).isEqualTo(1);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void givenChoiceModeIsNoneAndMultipleItemsAreChecked_whenGettingCheckedItemPositions_thenReturnNull() {
prepareListAdapter().withChoiceMode(ListView.CHOICE_MODE_NONE).withAnyItemsChecked();
assertNull(listView.getCheckedItemPositions());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void givenItemIsNotCheckedAndChoiceModeIsMultiple_whenPerformingItemClick_thenItemShouldBeChecked() {
prepareListAdapter().withChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
int positionToClick = anyListIndex();
listView.performItemClick(null, positionToClick, 0);
assertThat(listView.getCheckedItemPositions().get(positionToClick)).isTrue();
assertThat(listView.getCheckedItemCount()).isEqualTo(1);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void givenChoiceModeIsMultipleAndMultipleItemsAreChecked_whenGettingCheckedItemPositions_thenReturnCheckedPositions() {
prepareListAdapter().withChoiceMode(ListView.CHOICE_MODE_MULTIPLE).withAnyItemsChecked();
assertThat(listView.getCheckedItemCount()).isEqualTo(checkedItemPositions.size());
for (int i = 0; i < checkedItemPositions.size(); i++) {
assertThat(listView.getCheckedItemPositions().get(i)).isTrue();
}
}
代码示例来源:origin: stackoverflow.com
checked = list.getCheckedItemPositions();
for (int i = 0; i < checked.size(); i++) {
final int index = checked.keyAt(i);
checked = list.getCheckedItemPositions();
for (int i = 0; i < checked.size(); i++) {
final int index = checked.keyAt(i);
代码示例来源:origin: robolectric/robolectric
@Test
public void givenItemIsCheckedAndChoiceModeIsMultiple_whenPerformingItemClick_thenItemShouldNotBeChecked() {
prepareListAdapter().withChoiceMode(ListView.CHOICE_MODE_MULTIPLE).withAnyItemChecked();
listView.performItemClick(null, checkedItemPosition, 0);
assertFalse(listView.getCheckedItemPositions().get(checkedItemPosition));
}
代码示例来源:origin: andforce/iBeebo
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = activity.getLayoutInflater().inflate(R.layout.simple_listview_item, parent, false);
TextView tv = (TextView) view.findViewById(R.id.text1);
tv.setBackgroundColor(defaultBG);
if (listView.getCheckedItemPositions().get(position)) {
tv.setBackgroundColor(checkedBG);
}
tv.setText(list.get(position));
return view;
}
}
代码示例来源:origin: PrivacyApps/document-viewer
protected int getCheckedPositionsCount() {
final SparseBooleanArray checked = backupsList.getCheckedItemPositions();
int count = 0;
for (int i = 0, n = checked != null ? checked.size() : 0; i < n; i++) {
if (checked.valueAt(i)) {
count++;
}
}
return count;
}
代码示例来源:origin: nglauber/dominando_android2
private int qtdeItensMarcados() {
SparseBooleanArray checked = mListView.getCheckedItemPositions();
int checkedCount = 0;
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
checkedCount++;
}
}
return checkedCount;
}
代码示例来源:origin: nglauber/dominando_android2
private int qtdeItensMarcados() {
SparseBooleanArray checked = mListView.getCheckedItemPositions();
int checkedCount = 0;
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
checkedCount++;
}
}
return checkedCount;
}
代码示例来源:origin: AndBible/and-bible
private List<Integer> getSelecteditemPositions() {
SparseBooleanArray positionStates = list.getCheckedItemPositions();
List<Integer> selectedItemPositions = new ArrayList<>();
for (int i=0; i<positionStates.size(); i++) {
int position = positionStates.keyAt(i);
if (positionStates.get(position)) {
selectedItemPositions.add(position);
}
}
return selectedItemPositions;
}
代码示例来源:origin: nglauber/dominando_android2
private int qtdeItensMarcados() {
SparseBooleanArray checked = mListView.getCheckedItemPositions();
int checkedCount = 0;
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
checkedCount++;
}
}
return checkedCount;
}
代码示例来源:origin: nglauber/dominando_android2
private int qtdeItensMarcados() {
SparseBooleanArray checked = mListView.getCheckedItemPositions();
int checkedCount = 0;
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
checkedCount++;
}
}
return checkedCount;
}
代码示例来源:origin: nglauber/dominando_android2
private int qtdeItensMarcados() {
SparseBooleanArray checked = mListView.getCheckedItemPositions();
int checkedCount = 0;
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
checkedCount++;
}
}
return checkedCount;
}
代码示例来源:origin: googlecodelabs/android-topeka
@Override
protected boolean isAnswerCorrect() {
final SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
final int[] answer = getQuiz().getAnswer();
return AnswerHelper.isAnswerCorrect(checkedItemPositions, answer);
}
代码示例来源:origin: googlecodelabs/android-topeka
@Override
protected boolean isAnswerCorrect() {
final SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
final int[] answer = getQuiz().getAnswer();
return AnswerHelper.isAnswerCorrect(checkedItemPositions, answer);
}
内容来源于网络,如有侵权,请联系作者删除!