Search in sources :

Example 36 with ListView

use of android.widget.ListView in project platform_frameworks_base by android.

the class RenderSessionImpl method postInflateProcess.

/**
     * Post process on a view hierarchy that was just inflated.
     * <p/>
     * At the moment this only supports TabHost: If {@link TabHost} is detected, look for the
     * {@link TabWidget}, and the corresponding {@link FrameLayout} and make new tabs automatically
     * based on the content of the {@link FrameLayout}.
     * @param view the root view to process.
     * @param layoutlibCallback callback to the project.
     * @param skip the view and it's children are not processed.
     */
// For the use of Pair
@SuppressWarnings("deprecation")
private void postInflateProcess(View view, LayoutlibCallback layoutlibCallback, View skip) throws PostInflateException {
    if (view == skip) {
        return;
    }
    if (view instanceof TabHost) {
        setupTabHost((TabHost) view, layoutlibCallback);
    } else if (view instanceof QuickContactBadge) {
        QuickContactBadge badge = (QuickContactBadge) view;
        badge.setImageToDefault();
    } else if (view instanceof AdapterView<?>) {
        // get the view ID.
        int id = view.getId();
        BridgeContext context = getContext();
        // get a ResourceReference from the integer ID.
        ResourceReference listRef = context.resolveId(id);
        if (listRef != null) {
            SessionParams params = getParams();
            AdapterBinding binding = params.getAdapterBindings().get(listRef);
            // if there was no adapter binding, trying to get it from the call back.
            if (binding == null) {
                binding = layoutlibCallback.getAdapterBinding(listRef, context.getViewKey(view), view);
            }
            if (binding != null) {
                if (view instanceof AbsListView) {
                    if ((binding.getFooterCount() > 0 || binding.getHeaderCount() > 0) && view instanceof ListView) {
                        ListView list = (ListView) view;
                        boolean skipCallbackParser = false;
                        int count = binding.getHeaderCount();
                        for (int i = 0; i < count; i++) {
                            Pair<View, Boolean> pair = context.inflateView(binding.getHeaderAt(i), list, false, skipCallbackParser);
                            if (pair.getFirst() != null) {
                                list.addHeaderView(pair.getFirst());
                            }
                            skipCallbackParser |= pair.getSecond();
                        }
                        count = binding.getFooterCount();
                        for (int i = 0; i < count; i++) {
                            Pair<View, Boolean> pair = context.inflateView(binding.getFooterAt(i), list, false, skipCallbackParser);
                            if (pair.getFirst() != null) {
                                list.addFooterView(pair.getFirst());
                            }
                            skipCallbackParser |= pair.getSecond();
                        }
                    }
                    if (view instanceof ExpandableListView) {
                        ((ExpandableListView) view).setAdapter(new FakeExpandableAdapter(listRef, binding, layoutlibCallback));
                    } else {
                        ((AbsListView) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
                    }
                } else if (view instanceof AbsSpinner) {
                    ((AbsSpinner) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
                }
            }
        }
    } else if (view instanceof ViewGroup) {
        mInflater.postInflateProcess(view);
        ViewGroup group = (ViewGroup) view;
        final int count = group.getChildCount();
        for (int c = 0; c < count; c++) {
            View child = group.getChildAt(c);
            postInflateProcess(child, layoutlibCallback, skip);
        }
    }
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) AbsListView(android.widget.AbsListView) FakeAdapter(com.android.layoutlib.bridge.impl.binding.FakeAdapter) FakeExpandableAdapter(com.android.layoutlib.bridge.impl.binding.FakeExpandableAdapter) MenuView(com.android.internal.view.menu.MenuView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListView(android.widget.ListView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) AbsListView(android.widget.AbsListView) ActionMenuView(android.widget.ActionMenuView) ExpandableListView(android.widget.ExpandableListView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView) QuickContactBadge(android.widget.QuickContactBadge) AdapterBinding(com.android.ide.common.rendering.api.AdapterBinding) AbsSpinner(android.widget.AbsSpinner) AdapterView(android.widget.AdapterView) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) ExpandableListView(android.widget.ExpandableListView)

Example 37 with ListView

use of android.widget.ListView in project Android-MaterialRefreshLayout by android-cjj.

the class SunActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listview);
    String[] array = new String[50];
    for (int i = 0; i < array.length; i++) {
        array[i] = "啊哈哈哈哈哈 " + i;
    }
    final ListView listView = (ListView) findViewById(R.id.lv);
    listView.setAdapter(new android.widget.ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, array));
    materialRefreshLayout = (MaterialRefreshLayout) findViewById(R.id.refresh);
    materialRefreshLayout.setSunStyle(true);
    materialRefreshLayout.setMaterialRefreshListener(new MaterialRefreshListener() {

        @Override
        public void onRefresh(final MaterialRefreshLayout materialRefreshLayout) {
            materialRefreshLayout.postDelayed(new Runnable() {

                @Override
                public void run() {
                    materialRefreshLayout.finishRefresh();
                }
            }, 3000);
        }

        @Override
        public void onfinish() {
            Toast.makeText(SunActivity.this, "finish", Toast.LENGTH_LONG).show();
        }
    });
}
Also used : ListView(android.widget.ListView) MaterialRefreshListener(com.cjj.MaterialRefreshListener) MaterialRefreshLayout(com.cjj.MaterialRefreshLayout)

Example 38 with ListView

use of android.widget.ListView in project ListViewAnimations by nhaarman.

the class AdapterViewUtil method getViewForPosition.

/**
     * Returns the {@link View} that represents the item for given position.
     *
     * @param listViewWrapper the {@link ListViewWrapper} wrapping the ListView that should be examined
     * @param position        the position for which the {@code View} should be returned.
     *
     * @return the {@code View}, or {@code null} if the position is not currently visible.
     */
@Nullable
public static View getViewForPosition(@NonNull final ListViewWrapper listViewWrapper, final int position) {
    int childCount = listViewWrapper.getChildCount();
    View downView = null;
    for (int i = 0; i < childCount && downView == null; i++) {
        View child = listViewWrapper.getChildAt(i);
        if (child != null && getPositionForView(listViewWrapper, child) == position) {
            downView = child;
        }
    }
    return downView;
}
Also used : View(android.view.View) AbsListView(android.widget.AbsListView) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) Nullable(android.support.annotation.Nullable)

Example 39 with ListView

use of android.widget.ListView in project ListViewAnimations by nhaarman.

the class AbsListViewWrapperTest method testListViewGetHeaderViewsCount.

public void testListViewGetHeaderViewsCount() {
    ListView listView = mock(ListView.class);
    mAbsListViewWrapper = new AbsListViewWrapper(listView);
    when(listView.getHeaderViewsCount()).thenReturn(5);
    assertThat(mAbsListViewWrapper.getHeaderViewsCount(), is(5));
}
Also used : AbsListView(android.widget.AbsListView) ListView(android.widget.ListView)

Example 40 with ListView

use of android.widget.ListView in project android-demos by novoda.

the class JsonRequest method onResume.

@Override
protected void onResume() {
    super.onResume();
    Toast.makeText(this, "Querying droidcon on Twitter", Toast.LENGTH_SHORT).show();
    Reader reader = new InputStreamReader(retrieveStream(url));
    SearchResponse response = new Gson().fromJson(reader, SearchResponse.class);
    List<String> searches = new ArrayList<String>();
    Iterator<Result> i = response.results.iterator();
    while (i.hasNext()) {
        Result res = (Result) i.next();
        searches.add(res.text);
    }
    ListView v = (ListView) findViewById(R.id.list);
    v.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, searches.toArray(new String[searches.size()])));
}
Also used : ListView(android.widget.ListView) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Gson(com.google.gson.Gson) SearchResponse(com.novoda.model.SearchResponse) Result(com.novoda.model.Result)

Aggregations

ListView (android.widget.ListView)1139 View (android.view.View)739 AdapterView (android.widget.AdapterView)444 TextView (android.widget.TextView)389 ImageView (android.widget.ImageView)167 Intent (android.content.Intent)148 AbsListView (android.widget.AbsListView)135 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)97 ArrayAdapter (android.widget.ArrayAdapter)97 ArrayList (java.util.ArrayList)81 ViewGroup (android.view.ViewGroup)75 ListAdapter (android.widget.ListAdapter)71 OnClickListener (android.view.View.OnClickListener)65 LayoutInflater (android.view.LayoutInflater)63 Bundle (android.os.Bundle)57 Button (android.widget.Button)55 LinearLayout (android.widget.LinearLayout)50 SuppressLint (android.annotation.SuppressLint)34 DialogInterface (android.content.DialogInterface)34 ScrollView (android.widget.ScrollView)31