android.widget.Adapter.getItem()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中android.widget.Adapter.getItem()方法的一些代码示例,展示了Adapter.getItem()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Adapter.getItem()方法的具体详情如下:
包路径:android.widget.Adapter
类名称:Adapter
方法名:getItem

Adapter.getItem介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
  super.onCreateContextMenu(menu, v, menuInfo);

  // Get the info on which item was selected
  AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;

  // Get the Adapter behind your ListView (this assumes you're using
  // a ListActivity; if you're not, you'll have to store the Adapter yourself
  // in some way that can be accessed here.)
  Adapter adapter = getListAdapter();

  // Retrieve the item that was clicked on
  Object item = adapter.getItem(info.position);
}

@Override
public boolean onContextItemSelected(MenuItem item) {
  // Here's how you can get the correct item in onContextItemSelected()
  AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
  Object item = getListAdapter().getItem(info.position);
}

代码示例来源:origin: chentao0707/SimplifyReader

/**
 * Gets the data associated with the specified position in the list.
 *
 * @param position Which data to get
 * @return The data associated with the specified position in the list
 */
public Object getItemAtPosition(int position) {
  T adapter = getAdapter();
  return (adapter == null || position < 0) ? null : adapter.getItem(position);
}

代码示例来源:origin: lovetuzitong/MultiImageSelector

@Override
  public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    if (mImageAdapter.isShowCamera()) {
      if (i == 0) {
        showCameraAction();
      } else {
        Image image = (Image) adapterView.getAdapter().getItem(i);
        selectImageFromGrid(image, mode);
      }
    } else {
      Image image = (Image) adapterView.getAdapter().getItem(i);
      selectImageFromGrid(image, mode);
    }
  }
});

代码示例来源:origin: aporter/coursera-android

@Override
  public void onItemClick(AdapterView<?> arg0, View view, int arg2,
              long arg3) {
    Toast.makeText(getApplicationContext(),
        getString(R.string.winner_is_string, arg0.getAdapter().getItem(arg2)),
        Toast.LENGTH_LONG).show();
    textView.setText("");
  }
});

代码示例来源:origin: robolectric/robolectric

/**
 * @return the items that are available to be clicked on
 */
public CharSequence[] getItems() {
 Adapter adapter = getShadowAlertController().getAdapter();
 int count = adapter.getCount();
 CharSequence[] items = new CharSequence[count];
 for (int i = 0; i < items.length; i++) {
  items[i] = (CharSequence) adapter.getItem(i);
 }
 return items;
}

代码示例来源:origin: chentao0707/SimplifyReader

/**
 * @return The data corresponding to the currently selected item, or
 * null if there is nothing selected.
 */
public Object getSelectedItem() {
  T adapter = getAdapter();
  int selection = getSelectedItemPosition();
  if (adapter != null && adapter.getCount() > 0 && selection >= 0) {
    return adapter.getItem(selection);
  } else {
    return null;
  }
}

代码示例来源:origin: square/assertj-android

public S hasItem(Object expected, int index) {
 isNotNull();
 assertThat(actual.getCount())
   .overridingErrorMessage("Index %s is out of bounds. The adapter holds %s items.",
     index, actual.getCount())
   .isGreaterThan(index);
 final Object actualItem = actual.getItem(index);
 assertThat(actualItem)
   .overridingErrorMessage("Expected item at index %s to be <%s> but was <%s>.", index,
     expected, actualItem)
   .isEqualTo(expected);
 return myself;
}

代码示例来源:origin: jeasonlzy/ImagePicker

@Override
      public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
        mImageFolderAdapter.setSelectIndex(position);
        imagePicker.setCurrentImageFolderPosition(position);
        mFolderPopupWindow.dismiss();
        ImageFolder imageFolder = (ImageFolder) adapterView.getAdapter().getItem(position);
        if (null != imageFolder) {
//                    mImageGridAdapter.refreshData(imageFolder.images);
          mRecyclerAdapter.refreshData(imageFolder.images);
          mtvDir.setText(imageFolder.name);
        }
      }
    });

代码示例来源:origin: square/assertj-android

public S doesNotHaveItem(Object notExpected, int index) {
  isNotNull();

  assertThat(actual.getCount())
    .overridingErrorMessage("Index %s is out of bounds. The adapter holds %s items.",
      index, actual.getCount())
    .isGreaterThan(index);

  final Object actualItem = actual.getItem(index);
  assertThat(actualItem)
    .overridingErrorMessage("Expected item at index %s not to be <%s> but it was.", index,
      notExpected, actualItem)
    .isNotEqualTo(notExpected);

  return myself;
 }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testBuilderWithAdapter() throws Exception {
 List<Integer> list = new ArrayList<>();
 list.add(99);
 list.add(88);
 list.add(77);
 ArrayAdapter<Integer> adapter = new ArrayAdapter<>(context, R.layout.main, R.id.title, list);
 AlertDialog.Builder builder = new AlertDialog.Builder(application);
 builder.setSingleChoiceItems(adapter, -1, new DialogInterface.OnClickListener() {
  @Override
  public void onClick(DialogInterface dialog, int item) {
   dialog.dismiss();
  }
 });
 AlertDialog alert = builder.create();
 alert.show();
 assertTrue(alert.isShowing());
 ShadowAlertDialog shadowAlertDialog = shadowOf(alert);
 assertThat(shadowAlertDialog.getAdapter().getCount()).isEqualTo(3);
 assertThat(shadowAlertDialog.getAdapter().getItem(0)).isEqualTo(99);
}

代码示例来源:origin: googlemaps/android-samples

@Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    DemoDetails demo = (DemoDetails) parent.getAdapter().getItem(position);
    startActivity(new Intent(this, demo.activityClass));
  }
}

代码示例来源:origin: andyxialm/SmoothCheckBox

@Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Bean bean = (Bean) parent.getAdapter().getItem(position);
    bean.isChecked = !bean.isChecked;
    SmoothCheckBox checkBox = (SmoothCheckBox) view.findViewById(R.id.scb);
    checkBox.setChecked(bean.isChecked, true);
  }
});

代码示例来源:origin: xiepeijie/SwipeCardView

if(mActiveCard != null && mFlingListener != null) {
  flingCardListener = new FlingCardListener(mActiveCard, mAdapter.getItem(0),
      ROTATION_DEGREES, new FlingCardListener.FlingListener() {

代码示例来源:origin: com.actionbarsherlock/actionbarsherlock

/**
 * Gets the data associated with the specified position in the list.
 *
 * @param position Which data to get
 * @return The data associated with the specified position in the list
 */
public Object getItemAtPosition(int position) {
  T adapter = getAdapter();
  return (adapter == null || position < 0) ? null : adapter.getItem(position);
}

代码示例来源:origin: jp1017/ActivityLauncher

@Override
  public void onItemClick(AdapterView<?> view, View item, int index,
      long id) {
    Toast.makeText(getActivity(), view.getAdapter().getItem(index).toString(), Toast.LENGTH_SHORT).show();				
  }
});

代码示例来源:origin: stackoverflow.com

public List<User> retrieveAllItems(Spinner theSpinner) {
  Adapter adapter = theSpinner.getAdapter();
  int n = adapter.getCount();
  List<User> users = new ArrayList<User>(n);
  for (int i = 0; i < n; i++) {
    User user = (User) adapter.getItem(i);
    users.add(user);
  }
  return users;
}

代码示例来源:origin: com.github.japgolly.android.test/robolectric

@Implementation
public Object getItemAtPosition(int position) {
  Adapter adapter = getAdapter();
  return (adapter == null || position < 0) ? null : adapter.getItem(position);
}

代码示例来源:origin: sphinx02/AppStarter

@Override
  public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id)
  {
    // Get packagename of the app to be started
    mMovingApp[0] = (AppInfo) parent.getAdapter().getItem(position);
    mGridView.setDrawSelectorOnTop(true);
    mGridView.invalidate();
    Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.MoveAppAndClickToDrop), Toast.LENGTH_SHORT).show();
    return true;
  }
});

代码示例来源:origin: M66B/XPrivacyLua

@Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    DrawerItem item = (DrawerItem) parent.getAdapter().getItem(position);
    Log.i(TAG, "Drawer selected " + item.getTitle());
    item.onClick();
    if (!item.isCheckable())
      drawerLayout.closeDrawer(drawerList);
  }
});

代码示例来源:origin: mzule/AndroidWeekly

@OnItemClick(R.id.listView)
void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  String q = (String) parent.getAdapter().getItem(position);
  SearchHistoryKeeper.save(q);
  startActivity(SearchResultActivity.makeIntent(this, q));
}

相关文章