Example usage for android.widget ListView getHeaderViewsCount

List of usage examples for android.widget ListView getHeaderViewsCount

Introduction

In this page you can find the example usage for android.widget ListView getHeaderViewsCount.

Prototype

@Override
    public int getHeaderViewsCount() 

Source Link

Usage

From source file:Main.java

public static View getLiveListChild(ListView listView, int position) {
    int firstPosition = listView.getFirstVisiblePosition() - listView.getHeaderViewsCount(); // This is the same as child #0
    int wantedChild = position - firstPosition;
    // Say, first visible position is 8, you want position 10, wantedChild will now be 2
    // So that means your view is child #2 in the ViewGroup:
    if (wantedChild < 0 || wantedChild >= listView.getChildCount()) {
        return null;
    }// w  w w.  j a v a  2  s  .  c om
    return listView.getChildAt(wantedChild);
}

From source file:Main.java

public static int getAllListViewSectionCounts(ListView lv, List dataSource) {
    if (null == lv || dataSource == null || dataSource.isEmpty()) {
        return 0;
    }//from   w w w .  j  a v a 2 s  .c  o m
    return dataSource.size() + lv.getHeaderViewsCount() + lv.getFooterViewsCount();
}

From source file:sysnetlab.android.sdc.test.TestHelper.java

public static Activity viewMostRecentExperiment(ActivityInstrumentationTestCase2<?> testCase,
        Activity activity) {//ww  w .j  av a  2 s .  c  om
    // view the most recent experiment
    Fragment fragment = ((SensorDataCollectorActivity) activity).getSupportFragmentManager()
            .findFragmentById(R.id.fragment_container);
    Assert.assertNotNull("The Sensor List Fragment should not be null.", fragment);

    ListView listView = ((ListFragment) fragment).getListView();
    Assert.assertNotNull("ListView should not be null.", listView);

    ActivityMonitor monitor = testCase.getInstrumentation().addMonitor(ViewExperimentActivity.class.getName(),
            null, false);
    TouchUtils.clickView(testCase, listView.getChildAt(listView.getHeaderViewsCount()));
    testCase.getInstrumentation().waitForIdleSync();

    ViewExperimentActivity viewExperimentActivity = (ViewExperimentActivity) testCase.getInstrumentation()
            .waitForMonitor(monitor);
    Assert.assertTrue("activity should be a ViewExperimentActivity.",
            viewExperimentActivity instanceof ViewExperimentActivity);
    testCase.getInstrumentation().removeMonitor(monitor);

    // clone the experiment
    testCase.getInstrumentation().waitForIdleSync();
    return viewExperimentActivity;
}

From source file:com.oprisnik.semdroid.AppListFragment.java

@Override
public void onListItemClick(ListView l, View v, final int position, final long id) {
    int pos = position - l.getHeaderViewsCount();
    if (pos < 0) {
        return; // header view clicked
    }/*from  w w w  .  j av  a2s .  c o  m*/
    mCallbacks.onAppSelected(mAdapter.getItem(pos));
}

From source file:org.mariotaku.twidere.fragment.ActivitiesByFriendsFragment.java

@Override
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
    final int adapter_pos = position - l.getHeaderViewsCount();
    final ParcelableActivity item = getListAdapter().getItem(adapter_pos);
    if (item == null)
        return;/*from w w w  . j a v  a2s .c o  m*/
    final ParcelableUser[] sources = item.sources;
    final ParcelableStatus[] target_statuses = item.target_statuses;
    final ParcelableUser[] target_users = item.target_users;
    final int sources_length = sources != null ? sources.length : 0;
    final int target_statuses_length = target_statuses != null ? target_statuses.length : 0;
    final int target_users_length = target_users != null ? target_users.length : 0;
    if (sources_length > 0) {
        final ParcelableStatus[] target_object_statuses = item.target_object_statuses;
        switch (item.action) {
        case ParcelableActivity.ACTION_FAVORITE: {
            if (target_statuses_length == 1) {
                openStatus(getActivity(), target_statuses[0]);
            } else {
                final List<ParcelableStatus> statuses = Arrays.asList(target_statuses);
                openStatuses(getActivity(), statuses);
            }
            break;
        }
        case ParcelableActivity.ACTION_FOLLOW: {
            if (target_users_length == 1) {
                openUserProfile(getActivity(), target_users[0]);
            } else {
                final List<ParcelableUser> users = Arrays.asList(target_users);
                openUsers(getActivity(), users);
            }
            break;
        }
        case ParcelableActivity.ACTION_MENTION: {
            if (target_object_statuses != null && target_object_statuses.length > 0) {
                openStatus(getActivity(), target_object_statuses[0]);
            }
            break;
        }
        case ParcelableActivity.ACTION_REPLY: {
            if (target_statuses != null && target_statuses.length > 0) {
                openStatus(getActivity(), target_statuses[0]);
            }
            break;
        }
        case ParcelableActivity.ACTION_RETWEET: {
            if (target_statuses_length == 1) {
                openStatus(getActivity(), target_statuses[0]);
            } else {
                final List<ParcelableStatus> statuses = Arrays.asList(target_statuses);
                openStatuses(getActivity(), statuses);
            }
            break;
        }
        }
    }
}

From source file:de.vanita5.twittnuker.fragment.support.ActivitiesAboutMeFragment.java

@Override
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
    final int adapter_pos = position - l.getHeaderViewsCount();
    final ParcelableActivity item = getListAdapter().getItem(adapter_pos);
    if (item == null)
        return;/*from   w ww .  ja  v a  2s  . c  o  m*/
    final ParcelableUser[] sources = item.sources;
    if (sources == null || sources.length == 0)
        return;
    final ParcelableStatus[] target_statuses = item.target_statuses;
    final ParcelableStatus[] target_objects = item.target_object_statuses;
    switch (item.action) {
    case ParcelableActivity.ACTION_FAVORITE: {
        if (sources.length == 1) {
            openUserProfile(getActivity(), sources[0]);
        } else {
            final List<ParcelableUser> users = Arrays.asList(sources);
            openUsers(getActivity(), users);
        }
        break;
    }
    case ParcelableActivity.ACTION_FOLLOW: {
        if (sources.length == 1) {
            openUserProfile(getActivity(), sources[0]);
        } else {
            final List<ParcelableUser> users = Arrays.asList(sources);
            openUsers(getActivity(), users);
        }
        break;
    }
    case ParcelableActivity.ACTION_MENTION: {
        if (target_objects != null && target_objects.length > 0) {
            openStatus(getActivity(), target_objects[0]);
        }
        break;
    }
    case ParcelableActivity.ACTION_REPLY: {
        if (target_statuses != null && target_statuses.length > 0) {
            openStatus(getActivity(), target_statuses[0]);
        }
        break;
    }
    case ParcelableActivity.ACTION_RETWEET: {
        if (sources.length == 1) {
            openUserProfile(getActivity(), sources[0]);
        } else {
            final List<ParcelableUser> users = Arrays.asList(sources);
            openUsers(getActivity(), users);
        }
        break;
    }
    }
}

From source file:de.vanita5.twittnuker.fragment.support.ActivitiesByFriendsFragment.java

@Override
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
    final int adapterPos = position - l.getHeaderViewsCount();
    final ParcelableActivity item = getListAdapter().getItem(adapterPos);
    if (item == null)
        return;/*from  ww w. jav a2s . c om*/
    final ParcelableUser[] sources = item.sources;
    if (sources == null || sources.length == 0)
        return;
    final ParcelableStatus[] targetStatuses = item.target_statuses;
    final ParcelableUser[] targetUsers = item.target_users;
    final ParcelableStatus[] target_object_statuses = item.target_object_statuses;
    switch (item.action) {
    case ParcelableActivity.ACTION_FAVORITE: {
        if (targetStatuses == null || targetStatuses.length == 0)
            return;
        if (targetStatuses.length == 1) {
            openStatus(getActivity(), targetStatuses[0]);
        } else {
            final List<ParcelableStatus> statuses = Arrays.asList(targetStatuses);
            openStatuses(getActivity(), statuses);
        }
        break;
    }
    case ParcelableActivity.ACTION_FOLLOW: {
        if (targetUsers == null || targetUsers.length == 0)
            return;
        if (targetUsers.length == 1) {
            openUserProfile(getActivity(), targetUsers[0]);
        } else {
            final List<ParcelableUser> users = Arrays.asList(targetUsers);
            openUsers(getActivity(), users);
        }
        break;
    }
    case ParcelableActivity.ACTION_MENTION: {
        if (target_object_statuses != null && target_object_statuses.length > 0) {
            openStatus(getActivity(), target_object_statuses[0]);
        }
        break;
    }
    case ParcelableActivity.ACTION_REPLY: {
        if (targetStatuses != null && targetStatuses.length > 0) {
            openStatus(getActivity(), targetStatuses[0]);
        }
        break;
    }
    case ParcelableActivity.ACTION_RETWEET: {
        if (targetStatuses == null || targetStatuses.length == 0)
            return;
        if (targetStatuses.length == 1) {
            openStatus(getActivity(), targetStatuses[0]);
        } else {
            final List<ParcelableStatus> statuses = Arrays.asList(targetStatuses);
            openStatuses(getActivity(), statuses);
        }
        break;
    }
    }
}

From source file:can.yrt.onebusaway.MySearchStopsFragment.java

private void showOnMap(ListView l, int position) {
    ObaStop stop = (ObaStop) l.getAdapter().getItem(position - l.getHeaderViewsCount());
    final String stopId = stop.getId();
    final double lat = stop.getLatitude();
    final double lon = stop.getLongitude();

    HomeActivity.start(getActivity(), stopId, lat, lon);
}

From source file:can.yrt.onebusaway.MySearchStopsFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    ObaStop stop = (ObaStop) l.getAdapter().getItem(position - l.getHeaderViewsCount());
    final String shortcutName = stop.getName();

    ArrivalsListActivity.Builder b = new ArrivalsListActivity.Builder(getActivity(), stop);
    if (isShortcutMode()) {
        makeShortcut(shortcutName, b.getIntent());
    } else {//from ww  w. jav a2 s.  com
        b.setUpMode(NavHelp.UP_MODE_BACK);
        b.start();
    }
}

From source file:org.onebusaway.android.ui.MySearchStopsFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    ObaStop stop = (ObaStop) l.getAdapter().getItem(position - l.getHeaderViewsCount());
    final String shortcutName = stop.getName();

    // TODO - Pass in a route mapping?  Can we get away with just a stopId here?
    ArrivalsListActivity.Builder b = new ArrivalsListActivity.Builder(getActivity(), stop.getId());
    if (isShortcutMode()) {
        makeShortcut(shortcutName, b.getIntent());
    } else {/*w ww . j  a  v  a2  s  . c o m*/
        b.setUpMode(NavHelp.UP_MODE_BACK);
        b.start();
    }
}