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:org.onebusaway.android.ui.MySearchRoutesFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    // Get the adapter (this may or may not be a SimpleCursorAdapter)
    ListAdapter adapter = l.getAdapter();
    ObaRoute route = (ObaRoute) adapter.getItem(position - l.getHeaderViewsCount());
    final String routeId = route.getId();
    final String routeName = UIUtils.getRouteDisplayName(route);

    if (isShortcutMode()) {
        Intent intent = RouteInfoActivity.makeIntent(getActivity(), routeId);
        makeShortcut(routeName, intent);

    } else {// w  ww.  j  av  a  2  s  .c  om
        RouteInfoActivity.start(getActivity(), routeId);
    }
}

From source file:org.ubicompforall.cityexplorer.gui.ImportWebTab.java

@Override
public void onListItemClick(ListView l, View v, int pos, long id) {
    if (l.getAdapter().getItemViewType(pos) == SeparatedListAdapter.TYPE_SECTION_HEADER) {
        //Pressing a header
        debug(0, "Pressed a header... Dummy!");
    } else {//from  ww  w. ja  v a 2  s  . co m
        DB selectedDb = (DB) l.getAdapter().getItem(pos);
        //debug(2, "requestCode is "+ requestCode ); //RequestCode == 0
        debug(1, "I just found DB " + selectedDb.getLabel());

        String DEFAULT_DBFOLDER = getResources().getText(R.string.default_dbFolderName).toString();
        File currentDbFile = new File(
                getDatabasePath(DEFAULT_DBFOLDER).getAbsolutePath() + "/" + selectedDb.getLabel());
        //File currentDbFile = new File ( selectedDb.getURL().toString() );

        new SQLiteConnector(this, currentDbFile).createDbFromWeb(currentDbFile, selectedDb.getURL());
        DBFactory.changeInstance(this, currentDbFile);
        startActivity(new Intent(this, PlanActivity.class));
        finish();
    } //if header: skip, else select and finish
}

From source file:com.simplealertdialog.test.SupportActivityTest.java

public void testAdapter() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override//from  w  w  w .  j a va 2  s.  co m
        public void run() {
            activity.findViewById(com.simplealertdialog.test.R.id.btn_adapter).performClick();
            activity.getSupportFragmentManager().executePendingTransactions();
        }
    });
    getInstrumentation().waitForIdleSync();
    Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
    assertNotNull(f);
    Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
    assertNotNull(d);

    final ListView lv = (ListView) d.findViewById(R.id.list);
    assertNotNull(lv);
    assertTrue(lv.getAdapter() instanceof SweetsAdapter);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            lv.performItemClick(lv, 0, 0);
        }
    });
    getInstrumentation().waitForIdleSync();
}

From source file:com.xperia64.cosi.FsuviusFragment.java

private void updateFsu(String[] names, String[] fsu, String[] ids) {
    ///*from   w w w.  j a  v a  2 s .c o m*/

    ListView lv = ((ListView) rootView.findViewById(R.id.fsuList));
    if (lv.getAdapter() == null) {
        FsuviusListAdapter adapter = new FsuviusListAdapter(getActivity(), names, fsu, ids, this);
        lv.setAdapter(adapter);
    } else {
        ((FsuviusListAdapter) lv.getAdapter()).update(names, fsu, ids);

    }
}

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

private String[] getIds(ListView l, int position) {
    // Get the cursor and fetch the stop ID from that.
    SimpleCursorAdapter cursorAdapter = (SimpleCursorAdapter) l.getAdapter();
    final Cursor c = cursorAdapter.getCursor();
    c.moveToPosition(position - l.getHeaderViewsCount());
    final String[] result = new String[] { c.getString(COL_ID), c.getString(COL_STOP_ID),
            c.getString(COL_ROUTE_ID) };
    return result;
}

From source file:com.misczak.joinmybridge.EventFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Log.d("EventFragment", "Item clicked: " + id);

    Cursor listItemCursor = ((SimpleCursorAdapter) l.getAdapter()).getCursor();

    String eventId = listItemCursor.getString(listItemCursor.getColumnIndex(ID_COLUMN));
    String eventName = listItemCursor.getString(listItemCursor.getColumnIndex(TITLE_COLUMN));
    String eventLocation = listItemCursor.getString(listItemCursor.getColumnIndex(LOCATION_COLUMN)).trim();

    if (eventName.length() > BridgeFragment.MAX_NAME_LENGTH) {
        eventName = eventName.substring(0, BridgeFragment.MAX_NAME_LENGTH);
    }//from ww  w.  j  ava 2  s.com

    Log.d(TAG, "Event ID " + eventId);
    Log.d(TAG, "Event Title" + eventName);
    Log.d(TAG, "Event Location " + eventLocation);

    Intent i = new Intent(getActivity(), BridgeActivity.class);

    i.putExtra(BridgeFragment.EXTRA_BRIDGE_NAME, eventName);

    ImportUtilities iu = new ImportUtilities();
    String[] bridgeComponents = iu.getNumberArray(eventLocation);

    if (bridgeComponents[0] != null && !bridgeComponents[0].isEmpty()) {
        i.putExtra(BridgeFragment.EXTRA_BRIDGE_NUMBER, bridgeComponents[0]);
    }
    if (bridgeComponents[1] != null && !bridgeComponents[1].isEmpty()) {
        i.putExtra(BridgeFragment.EXTRA_PARTICIPANT_CODE, bridgeComponents[1]);
    }
    if (bridgeComponents[2] != null && !bridgeComponents[2].isEmpty()) {
        i.putExtra(BridgeFragment.EXTRA_HOST_CODE, bridgeComponents[2]);
    }
    if (bridgeComponents[3] != null && !bridgeComponents[3].isEmpty()) {
        i.putExtra(BridgeFragment.EXTRA_FIRST_TONE, bridgeComponents[3]);
    }
    if (bridgeComponents[4] != null && !bridgeComponents[4].isEmpty()) {
        i.putExtra(BridgeFragment.EXTRA_SECOND_TONE, bridgeComponents[4]);
    }

    startActivityForResult(i, 0);

}

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

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Contact contact = (Contact) l.getAdapter().getItem(position);

    Client client = Client.getInstance();
    Pond.Message.Builder msg = Pond.Message.newBuilder();
    msg.setId(client.randId());//from w  ww  .java2  s.  com
    client.registerId(msg.getId());
    //    msg.setBody(ByteString.copyFrom(Globals.lastImageTaken));
    msg.setBody(ByteString.copyFromUtf8("test"));
    msg.setTime(System.nanoTime());
    Network.send(contact, msg);
    Intent contactPage = new Intent(getActivity(), CameraActivity.class);
    //      contactPage.putExtra("contact_id", position);
    contactPage.putExtra("master_secret", masterSecret);
    startActivity(contactPage);
    //    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:org.mozilla.gecko.tests.AboutHomeTest.java

protected View getDisplayedBookmark(String url) {
    openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
    mSolo.hideSoftKeyboard();//from  w w w  .  j av a  2  s  . co  m
    getInstrumentation().waitForIdleSync();
    ListView bookmarksTabList = findListViewWithTag(HomePager.LIST_TAG_BOOKMARKS);
    waitForNonEmptyListToLoad(bookmarksTabList);
    ListAdapter adapter = bookmarksTabList.getAdapter();
    if (adapter != null) {
        for (int i = 0; i < adapter.getCount(); i++) {
            // I am unable to click the view taken with getView for some reason so getting the child at i
            bookmarksTabList.smoothScrollToPosition(i);
            View bookmarkView = bookmarksTabList.getChildAt(i);
            if (bookmarkView instanceof android.widget.LinearLayout) {
                ViewGroup bookmarkItemView = (ViewGroup) bookmarkView;
                for (int j = 0; j < bookmarkItemView.getChildCount(); j++) {
                    View bookmarkContent = bookmarkItemView.getChildAt(j);
                    if (bookmarkContent instanceof android.widget.LinearLayout) {
                        ViewGroup bookmarkItemLayout = (ViewGroup) bookmarkContent;
                        for (int k = 0; k < bookmarkItemLayout.getChildCount(); k++) {
                            // Both the title and url are represented as text views so we can cast the view without any issues
                            TextView bookmarkTextContent = (TextView) bookmarkItemLayout.getChildAt(k);
                            if (url.equals(bookmarkTextContent.getText().toString())) {
                                return bookmarkView;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}

From source file:com.simplealertdialog.test.FragmentSupportActivityTest.java

public void testItems() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override/*from w w w .  ja  v  a 2s . com*/
        public void run() {
            Fragment f = activity.getSupportFragmentManager().findFragmentById(R.id.fragment_sample);
            assertNotNull(f);
            assertNotNull(f.getView());
            f.getView().findViewById(R.id.btn_frag_items).performClick();
            activity.getFragmentManager().executePendingTransactions();
        }
    });
    getInstrumentation().waitForIdleSync();
    Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
    assertNotNull(f);
    Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
    assertNotNull(d);

    final ListView lv = (ListView) d.findViewById(R.id.list);
    assertNotNull(lv);
    assertTrue(lv.getAdapter() instanceof ArrayAdapter<?>);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            lv.performItemClick(lv, 0, 0);
        }
    });
}

From source file:com.simplealertdialog.test.FragmentSupportActivityTest.java

public void testItemsWithIcons() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override/*from www. j  a  va  2  s .c  om*/
        public void run() {
            Fragment f = activity.getSupportFragmentManager().findFragmentById(R.id.fragment_sample);
            assertNotNull(f);
            assertNotNull(f.getView());
            f.getView().findViewById(R.id.btn_frag_icon_items).performClick();
            activity.getFragmentManager().executePendingTransactions();
        }
    });
    getInstrumentation().waitForIdleSync();
    Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
    assertNotNull(f);
    Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
    assertNotNull(d);

    final ListView lv = (ListView) d.findViewById(R.id.list);
    assertNotNull(lv);
    assertTrue(lv.getAdapter() instanceof ArrayAdapter<?>);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            lv.performItemClick(lv, 0, 0);
        }
    });
}