Example usage for android.widget ListView getAdapter

List of usage examples for android.widget ListView getAdapter

Introduction

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

Prototype

@Override
public ListAdapter getAdapter() 

Source Link

Document

Returns the adapter currently in use in this ListView.

Usage

From source file:com.pemikir.youtubeplus.VideoItemListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    videoListAdapter = new VideoListAdapter(getActivity(), this);
    setListAdapter(videoListAdapter);// ww  w.j a v a  2  s.co  m

    // Restore the previously serialized activated item position.
    if (savedInstanceState != null

            && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
        setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
    }

    getListView().setOnScrollListener(new AbsListView.OnScrollListener() {
        private static final float OVERSCROLL_THRESHOLD_IN_PIXELS = 100;
        long lastScrollDate = 0;
        private float downY;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            ListView list = getListView();
            if (list.getChildAt(0) != null && list.getLastVisiblePosition() == list.getAdapter().getCount() - 1
                    && list.getChildAt(list.getChildCount() - 1).getBottom() <= list.getHeight()) {
                long time = System.currentTimeMillis();
                if ((time - lastScrollDate) > 200) {
                    lastScrollDate = time;
                    nextPage();
                }
            }
        }

    });
}

From source file:systems.obscure.client.ContactsListFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Intent contactPage = new Intent(getActivity(), ContactActivity.class);
    contactPage.putExtra("contact_id", ((Contact) l.getAdapter().getItem(position)).id);
    contactPage.putExtra("master_secret", masterSecret);
    startActivity(contactPage);//  w  ww  .j a  v a 2 s .co m
    //    if (v instanceof ContactsListItem) {
    //      ContactsListItem headerView = (ContactsListItem) v;
    //      if (actionMode == null) {
    //        handleCreateConversation(headerView.getThreadId(), headerView.getRecipients(),
    //                                 headerView.getDistributionType());
    //      } else {
    //        ContactListAdapter adapter = (ContactListAdapter)getListAdapter();
    //        adapter.toggleThreadInBatchSet(headerView.getThreadId());
    //
    //        if (adapter.getBatchSelections().size() == 0) {
    //          actionMode.finish();
    //        } else {
    //          actionMode.setSubtitle(getString(R.string.conversation_fragment_cab__batch_selection_amount,
    //                                           adapter.getBatchSelections().size()));
    //        }
    //
    //        adapter.notifyDataSetChanged();
    //      }
    //    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapterv2.java

public void justifyListViewHeightBasedOnChildren(ListView listView) {
    ArrayAdapter adapter = (ArrayAdapter) listView.getAdapter();

    if (adapter == null) {
        return;//from  ww  w.  j  a va2  s .  c o m
    }
    ViewGroup vg = listView;
    int totalHeight = 0;
    for (int i = 0; i < adapter.getCount(); i++) {
        View listItem = adapter.getView(i, null, vg);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams par = listView.getLayoutParams();
    par.height = totalHeight + (listView.getDividerHeight() * (adapter.getCount() - 1));
    listView.setLayoutParams(par);
    listView.requestLayout();
}

From source file:com.cachirulop.moneybox.fragment.MovementsFragment.java

/**
 * Refresh the list of movements. Call to the adapter of the ListView with
 * the movements to refresh the information.
 *//*w ww  .java2s .co  m*/
public void refresh() {
    ListView listView;
    MoneyboxMovementAdapter adapter;
    MainActivity parent;

    parent = (MainActivity) getActivity();

    listView = (ListView) getActivity().findViewById(R.id.lvMovements);

    adapter = (MoneyboxMovementAdapter) listView.getAdapter();
    adapter.setMoneybox(parent.getCurrentMoneybox());
    adapter.refreshMovements();

    updateTotal();
}

From source file:com.zawadz88.realestate.test.MainActivityTest.java

@FlakyTest
public void testContentReplacementOnNavigationDrawerListItemClicked() {
    final int articlesPosition = Section.ARTICLES.getPosition();
    final ListView listView = (ListView) solo.getView(com.zawadz88.realestate.R.id.navigation_list);
    assertEquals(solo.getString(com.zawadz88.realestate.R.string.section_title_ads),
            getActivity().getActionBarTitle());
    getActivity().runOnUiThread(new Runnable() {
        @Override//from  w ww . jav  a 2  s  .  com
        public void run() {
            listView.performItemClick(listView.getAdapter().getView(articlesPosition, null, null),
                    articlesPosition, listView.getAdapter().getItemId(articlesPosition));
        }
    });
    Condition titleChangedCondition = new Condition() {
        @Override
        public boolean isSatisfied() {
            return solo.getString(com.zawadz88.realestate.R.string.section_title_articles)
                    .equals(getActivity().getActionBarTitle());
        }
    };
    assertTrue(solo.waitForCondition(titleChangedCondition, 2000));
}

From source file:net.named_data.nfd.RouteListFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    if (m_callbacks != null) {
        RibEntry ribEntry = (RibEntry) l.getAdapter().getItem(position);
        m_callbacks.onRouteItemSelected(ribEntry);
    }/*w w  w.  ja  v  a2  s  . c om*/
}

From source file:com.frostwire.android.gui.fragments.SlideMenuFragment.java

@Override
public void onListItemClick(ListView lv, View v, int position, long id) {
    if (getActivity() == null) {
        return;// w  w w  .j  ava 2 s  .  com
    }

    try {
        MenuAdapter adapter = (MenuAdapter) lv.getAdapter();
        MenuItem item = (MenuItem) adapter.getItem(position);
        if (item.id == R.id.menu_main_preferences) {
            adapter.notifyDataSetChanged();
            showPreferences(getActivity());
        } else if (item.id == R.id.menu_launch_tv) {
            launchFrostWireTV();
        } else if (item.id == R.id.menu_free_apps) {
            showFreeApps();
        } else {
            adapter.setSelectedItem(item.id);
            switchFragment(item.id);
        }
    } catch (Throwable e) { // protecting from weird android UI engine issues
        LOG.error("Error clicking slide menu item", e);
    }
}

From source file:de.damdi.fitness.activity.start_training.FExListFragment.java

@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
    super.onListItemClick(listView, view, position, id);

    // Notify the active callbacks interface (the activity, if the
    // fragment is attached to one) that an item has been selected.
    mCallbacks.onItemSelected((FitnessExercise) listView.getAdapter().getItem(position));
}

From source file:com.sftoolworks.nfcoptions.SelectActivity.java

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {

    ListView list = (ListView) findViewById(R.id.listView1);
    if (list.getCount() > 0) {
        savedInstanceState.putBooleanArray(CHECKBOX_STATE,
                ((OptionListAdapter) list.getAdapter()).getCheckState());
    }//from ww w .j  a  v  a  2s.c om
    if (null != selectKey)
        savedInstanceState.putString(KEY_STATE, selectKey);

    // Always call the superclass so it can save the view hierarchy state
    super.onSaveInstanceState(savedInstanceState);
}

From source file:com.cachirulop.moneybox.fragment.MovementsFragment.java

/**
 * Creates a context menu for the list of movements, showing an option for
 * delete the movement and another to get the movement.
 *//*from  w  ww  . ja  v  a  2s. c  om*/
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    if (v.getId() == R.id.lvMovements) {
        AdapterView.AdapterContextMenuInfo info;
        ListView listView;
        Movement selected;

        listView = (ListView) getActivity().findViewById(R.id.lvMovements);
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;

        selected = (Movement) ((MoneyboxMovementAdapter) listView.getAdapter()).getItem(info.position);

        MenuItem item;

        menu.setHeaderTitle(selected.getInsertDateFormatted());
        item = menu.add(Menu.NONE, CONTEXT_MENU_GET, 0, R.string.get_from_moneybox);
        item.setEnabled(MovementsManager.canGetMovement(selected));

        item = menu.add(Menu.NONE, CONTEXT_MENU_DROP, 1, R.string.drop_to_moneybox_again);
        item.setEnabled(MovementsManager.canDropMovement(selected));

        item = menu.add(Menu.NONE, CONTEXT_MENU_DELETE, 2, R.string.delete);
        item.setEnabled(MovementsManager.canDeleteMovement(selected));
    }
}