本文整理了Java中android.widget.Adapter
类的一些代码示例,展示了Adapter
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Adapter
类的具体详情如下:
包路径:android.widget.Adapter
类名称:Adapter
暂无
代码示例来源: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: square/assertj-android
public S isNotEmpty() {
isNotNull();
assertThat(actual.isEmpty()) //
.overridingErrorMessage("Expected to not be empty but was.") //
.isFalse();
return myself;
}
代码示例来源:origin: chentao0707/SimplifyReader
/**
* Remember enough information to restore the screen state when the data has
* changed.
*
*/
void rememberSyncState() {
if (getChildCount() > 0) {
mNeedSync = true;
mSyncHeight = mLayoutHeight;
// Sync the based on the offset of the first view
View v = getChildAt(0);
T adapter = getAdapter();
if (mFirstPosition >= 0 && mFirstPosition < adapter.getCount()) {
mSyncRowId = adapter.getItemId(mFirstPosition);
} else {
mSyncRowId = NO_ID;
}
mSyncPosition = mFirstPosition;
if (v != null) {
mSpecificTop = v.getTop();
}
mSyncMode = SYNC_FIRST_POSITION;
}
}
}
代码示例来源:origin: stackoverflow.com
/**
* Computes the widest view in an adapter, best used when you need to wrap_content on a ListView, please be careful
* and don't use it on an adapter that is extremely numerous in items or it will take a long time.
*
* @param context Some context
* @param adapter The adapter to process
* @return The pixel width of the widest View
*/
public static int getWidestView(Context context, Adapter adapter) {
int maxWidth = 0;
View view = null;
FrameLayout fakeParent = new FrameLayout(context);
for (int i=0, count=adapter.getCount(); i<count; i++) {
view = adapter.getView(i, view, fakeParent);
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int width = view.getMeasuredWidth();
if (width > maxWidth) {
maxWidth = width;
}
}
return maxWidth;
}
代码示例来源: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: com.actionbarsherlock/actionbarsherlock
void checkFocus() {
final T adapter = getAdapter();
final boolean empty = adapter == null || adapter.getCount() == 0;
final boolean focusable = !empty || isInFilterMode();
// The order in which we set focusable in touch mode/focusable may matter
// for the client, see View.setFocusableInTouchMode() comments for more
// details
super.setFocusableInTouchMode(focusable && mDesiredFocusableInTouchModeState);
super.setFocusable(focusable && mDesiredFocusableState);
if (mEmptyView != null) {
updateEmptyStatus((adapter == null) || adapter.isEmpty());
}
}
代码示例来源:origin: square/assertj-android
public S hasCount(int count) {
isNotNull();
int actualCount = actual.getCount();
assertThat(actualCount) //
.overridingErrorMessage("Expected count <%s> but was <%s>.", count, actualCount) //
.isEqualTo(count);
return myself;
}
代码示例来源:origin: stackoverflow.com
mAdapter.unregisterDataSetObserver(mDataSetObserver);
mAdapter.registerDataSetObserver(mDataSetObserver);
final int dataPosition = i - getHeaderViewsCount();
final int childPosition = i - getFirstVisiblePosition();
if (dataPosition >= 0 && dataPosition < mAdapter.getCount()
&& getChildAt(childPosition) != null) {
Log.v(TAG, "Refreshing view (data=" + dataPosition + ",child=" + childPosition + ")");
mAdapter.getView(dataPosition, getChildAt(childPosition), this);
代码示例来源:origin: quaap/LaunchTime
@Override
public void onClick(View view) {
onItemClick(staticListView.mAdapter.getItem(pos), itemView, pos, staticListView.mAdapter.getItemId(pos));
}
});
代码示例来源:origin: chentao0707/SimplifyReader
public long getItemIdAtPosition(int position) {
T adapter = getAdapter();
return (adapter == null || position < 0) ? INVALID_ROW_ID : adapter.getItemId(position);
}
代码示例来源:origin: stackoverflow.com
// ListView myListView = the ListView in question
// int selectedRow = the currently selected row in the ListView
// Each row in the ListView is backed by an object of type MyCustomDataClass
int dbRowId;
Adapter adapter = myListView.getAdapter();
MyCustomDataClass data = (MyCustomDataClass) adapter.getItem(selectedRow);
dbRowId = data.getDatabaseRowId();
// OR
dbRowId = data.rowId;
// OR whatever method the object has for getting the ID.
// OR
View listViewRow = adapter.getView(selectedRow);
TextView dbRowView = (TextView) listViewRow.findViewById(R.id.rowid);
String dbRowAsString = dbRowView.getText().toString();
dbRowId = Integer.parseInt(dbRowAsString);
代码示例来源:origin: robolectric/robolectric
public int findIndexOfItemContainingText(String targetText) {
for (int i = 0; i < realAdapterView.getCount(); i++) {
View childView = realAdapterView.getAdapter().getView(i, null, new FrameLayout(realAdapterView.getContext()));
ShadowView shadowView = Shadow.extract(childView);
String innerText = shadowView.innerText();
if (innerText.contains(targetText)) {
return i;
}
}
return -1;
}
代码示例来源:origin: stackoverflow.com
public class HeaderAdapter{
private Adapter mAdapter; // this adapter is the adapter that you will normally have, for your listview
getViewTypeCount(){
return mAdapter.getViewTypeCount() + 1;
}
getView(int pos, View convertView){
// Handle only the first position, othervise, let mAdapter return
if (pos!=0) return mAdapter.getView(pos-1, convertView);
//
View v = LayoutInflater.inflate(R.layout.other_linear_layout);
// Bind the v if necessary
return v;
}
}
代码示例来源: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: dalong982242260/CarrouselView
void checkFocus() {
final T adapter = getAdapter();
final boolean empty = adapter == null || adapter.getCount() == 0;
final boolean focusable = !empty || isInFilterMode();
// The order in which we set focusable in touch mode/focusable may matter
// for the client, see View.setFocusableInTouchMode() comments for more
// details
super.setFocusableInTouchMode(focusable && mDesiredFocusableInTouchModeState);
super.setFocusable(focusable && mDesiredFocusableState);
if (mEmptyView != null) {
updateEmptyStatus((adapter == null) || adapter.isEmpty());
}
}
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public void check(View view,
NoMatchingViewException noViewFoundException) {
Assert.assertTrue(view instanceof AdapterView);
Assert.assertEquals(count,
((AdapterView)view).getAdapter().getCount());
}
}
代码示例来源:origin: GeekGhost/Ghost
private void addNextCard() {
if (nextAdapterCard < mAdapter.getCount()) {
// TODO: Make view recycling work
// TODO: Instead of removing the view from here and adding it again when it's swiped
// ... don't remove and add to this instance: don't call removeView & addView in sequence.
View newBottomChild = mAdapter.getView(nextAdapterCard, null/*lastRemovedView*/, this);
if (hardwareAccelerationEnabled) {
//set backed by an off-screen buffer
newBottomChild.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
//set the initial Y value so card appears from under the deck
//newBottomChild.setY(paddingTop);
addAndMeasureChild(newBottomChild);
nextAdapterCard++;
}
setupTopCard();
}
代码示例来源:origin: chentao0707/SimplifyReader
rowId = adapter.getItemId(seed);
if (rowId == idToMatch) {
代码示例来源:origin: androidquery/androidquery
adapter.getView(drawPos, convertView, parent);
代码示例来源: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;
}
}
内容来源于网络,如有侵权,请联系作者删除!