Search in sources :

Example 81 with ListAdapter

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);
}
Also used : ListView(android.widget.ListView) Button(android.widget.Button) ListAdapter(android.widget.ListAdapter)

Example 82 with ListAdapter

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);
}
Also used : AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) MenuItem(android.view.MenuItem) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter) Nullable(android.annotation.Nullable)

Example 83 with ListAdapter

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);
}
Also used : FloatingActionButton(com.marshalchen.common.ui.FloatingActionButtonWithListView.FloatingActionButton) ListAdapter(android.widget.ListAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Example 84 with 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);
            }
        }
    }
}
Also used : Tintable(com.bilibili.magicasakura.widgets.Tintable) ViewGroup(android.view.ViewGroup) AbsListView(android.widget.AbsListView) InvocationTargetException(java.lang.reflect.InvocationTargetException) RecyclerView(android.support.v7.widget.RecyclerView) BaseAdapter(android.widget.BaseAdapter) ListAdapter(android.widget.ListAdapter) WrapperListAdapter(android.widget.WrapperListAdapter) WrapperListAdapter(android.widget.WrapperListAdapter)

Example 85 with ListAdapter

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);
}
Also used : HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter) WrapperListAdapter(android.widget.WrapperListAdapter)

Aggregations

ListAdapter (android.widget.ListAdapter)298 ListView (android.widget.ListView)105 View (android.view.View)96 AdapterView (android.widget.AdapterView)55 AbsListView (android.widget.AbsListView)48 WrapperListAdapter (android.widget.WrapperListAdapter)47 HeaderViewListAdapter (android.widget.HeaderViewListAdapter)44 TextView (android.widget.TextView)42 ViewGroup (android.view.ViewGroup)37 Paint (android.graphics.Paint)22 ArrayAdapter (android.widget.ArrayAdapter)21 Point (android.graphics.Point)19 SuppressLint (android.annotation.SuppressLint)16 SimpleCursorAdapter (android.widget.SimpleCursorAdapter)16 Cursor (android.database.Cursor)12 SectionIndexer (android.widget.SectionIndexer)11 DialogInterface (android.content.DialogInterface)10 Bundle (android.os.Bundle)10 FrameLayout (android.widget.FrameLayout)10 GridView (android.widget.GridView)10