use of android.widget.ListAdapter in project android_frameworks_base by ResurrectionRemix.
the class ListWithHeaders method onCreate.
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
final ListView listView = getListView();
listView.setItemsCanFocus(true);
for (int i = 0; i < 12; i++) {
Button header = new Button(this);
header.setText("Header View");
listView.addHeaderView(header);
}
for (int i = 0; i < 12; i++) {
Button footer = new Button(this);
footer.setText("Footer View");
listView.addFooterView(footer);
}
final ListAdapter adapter = listView.getAdapter();
listView.setAdapter(adapter);
}
use of android.widget.ListAdapter in project android_frameworks_base by ResurrectionRemix.
the class CascadingMenuPopup method findParentViewForSubmenu.
/**
* Attempts to find the view for the menu item that owns the specified
* submenu.
*
* @param parentInfo info for the parent menu
* @param submenu the submenu whose parent view should be obtained
* @return the parent view, or {@code null} if one could not be found
*/
@Nullable
private View findParentViewForSubmenu(@NonNull CascadingMenuInfo parentInfo, @NonNull MenuBuilder submenu) {
final MenuItem owner = findMenuItemForSubmenu(parentInfo.menu, submenu);
if (owner == null) {
// Couldn't find the submenu owner.
return null;
}
// The adapter may be wrapped. Adjust the index if necessary.
final int headersCount;
final MenuAdapter menuAdapter;
final ListView listView = parentInfo.getListView();
final ListAdapter listAdapter = listView.getAdapter();
if (listAdapter instanceof HeaderViewListAdapter) {
final HeaderViewListAdapter headerAdapter = (HeaderViewListAdapter) listAdapter;
headersCount = headerAdapter.getHeadersCount();
menuAdapter = (MenuAdapter) headerAdapter.getWrappedAdapter();
} else {
headersCount = 0;
menuAdapter = (MenuAdapter) listAdapter;
}
// Find the index within the menu adapter's data set of the menu item.
int ownerPosition = AbsListView.INVALID_POSITION;
for (int i = 0, count = menuAdapter.getCount(); i < count; i++) {
if (owner == menuAdapter.getItem(i)) {
ownerPosition = i;
break;
}
}
if (ownerPosition == AbsListView.INVALID_POSITION) {
// Couldn't find the owner within the menu adapter.
return null;
}
// Adjust the index for the adapter used to display views.
ownerPosition += headersCount;
// Adjust the index for the visible views.
final int ownerViewPosition = ownerPosition - listView.getFirstVisiblePosition();
if (ownerViewPosition < 0 || ownerViewPosition >= listView.getChildCount()) {
// Not visible on screen.
return null;
}
return listView.getChildAt(ownerViewPosition);
}
use of android.widget.ListAdapter in project UltimateAndroid by cymcsg.
the class FloatingActionButtonDemo method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.floating_action_button_demo);
FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.button_floating_action);
floatingActionButton.attachToListView(getListView());
ListAdapter listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.countries));
getListView().setAdapter(listAdapter);
}
use of android.widget.ListAdapter in project MagicaSakura by Bilibili.
the class ThemeUtils method refreshView.
private static void refreshView(View view, ExtraRefreshable extraRefreshable) {
if (view == null)
return;
view.destroyDrawingCache();
if (view instanceof Tintable) {
((Tintable) view).tint();
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
refreshView(((ViewGroup) view).getChildAt(i), extraRefreshable);
}
}
} else {
if (extraRefreshable != null) {
extraRefreshable.refreshSpecificView(view);
}
if (view instanceof AbsListView) {
try {
if (sRecyclerBin == null) {
sRecyclerBin = AbsListView.class.getDeclaredField("mRecycler");
sRecyclerBin.setAccessible(true);
}
if (sListViewClearMethod == null) {
sListViewClearMethod = Class.forName("android.widget.AbsListView$RecycleBin").getDeclaredMethod("clear");
sListViewClearMethod.setAccessible(true);
}
sListViewClearMethod.invoke(sRecyclerBin.get(view));
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
ListAdapter adapter = ((AbsListView) view).getAdapter();
while (adapter instanceof WrapperListAdapter) {
adapter = ((WrapperListAdapter) adapter).getWrappedAdapter();
}
if (adapter instanceof BaseAdapter) {
((BaseAdapter) adapter).notifyDataSetChanged();
}
}
if (view instanceof RecyclerView) {
try {
if (sRecycler == null) {
sRecycler = RecyclerView.class.getDeclaredField("mRecycler");
sRecycler.setAccessible(true);
}
if (sRecycleViewClearMethod == null) {
sRecycleViewClearMethod = Class.forName("android.support.v7.widget.RecyclerView$Recycler").getDeclaredMethod("clear");
sRecycleViewClearMethod.setAccessible(true);
}
sRecycleViewClearMethod.invoke(sRecycler.get(view));
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
((RecyclerView) view).getRecycledViewPool().clear();
((RecyclerView) view).invalidateItemDecorations();
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
refreshView(((ViewGroup) view).getChildAt(i), extraRefreshable);
}
}
}
}
use of android.widget.ListAdapter in project AStickyHeader by DWorkS.
the class PinnedSectionGridView method setAdapter.
@Override
public void setAdapter(ListAdapter adapter) {
// assert adapter in debug mode
if (BuildConfig.DEBUG && adapter != null) {
if (!(adapter instanceof PinnedSectionGridAdapter))
throw new IllegalArgumentException("Does your adapter implement PinnedSectionGridAdapter?");
if (adapter.getViewTypeCount() < 2)
throw new IllegalArgumentException("Does your adapter handle at least two types" + " of views in getViewTypeCount() method: items and sections?");
}
// unregister observer at old adapter and register on new one
ListAdapter oldAdapter = getAdapter();
if (oldAdapter != null)
oldAdapter.unregisterDataSetObserver(mDataSetObserver);
if (adapter != null)
adapter.registerDataSetObserver(mDataSetObserver);
// destroy pinned shadow, if new adapter is not same as old one
if (oldAdapter != adapter)
destroyPinnedShadow();
super.setAdapter(adapter);
}
Aggregations