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.simplealertdialog.test.FragmentSupportActivityTest.java

public void testAdapter() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override/* w  w  w.ja v a 2s  .  co m*/
        public void run() {
            Fragment f = activity.getSupportFragmentManager().findFragmentById(R.id.fragment_sample);
            assertNotNull(f);
            assertNotNull(f.getView());
            f.getView().findViewById(R.id.btn_frag_adapter).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 SweetsAdapter);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            lv.performItemClick(lv, 0, 0);
        }
    });
}

From source file:com.glabs.homegenie.fragments.GroupsViewFragment.java

public void UpdateCurrentGroupModules() {
    ArrayList<Module> modules = null;
    try {//from w  ww  .j  a  v a2 s.  c o m
        modules = mAdapter.getGroup(mCurrentGroup).Modules;
    } catch (Exception e) {
    }
    //
    if (modules == null)
        return;
    //
    ArrayList<Module> controlModules = new ArrayList<Module>();
    mGroupPrograms.clear();
    for (Module m : modules) {
        if (m == null)
            continue;
        ModuleParameter widgetParam = m.getParameter("Widget.DisplayModule");
        String widget = "";
        if (widgetParam != null)
            widget = widgetParam.Value;
        if (widget.equals("homegenie/generic/program")) {
            mGroupPrograms.add(m);
        } else {
            controlModules.add(m);
        }
    }
    //
    GroupFragment f = mAdapter.getItem(mCurrentGroup);
    View v = f.getView();
    if (v != null) {
        ListView lv = (ListView) v.findViewById(R.id.listView);
        if (lv.getAdapter() == null) {
            ModulesAdapter adapter;
            adapter = new ModulesAdapter(v.getContext(), R.layout.widget_item_generic, controlModules);
            mAdapterList.put(mCurrentGroup, adapter);
            lv.setAdapter(adapter);
            lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    Module module = (Module) view.getTag();
                    if (module != null && module.Adapter != null) {
                        ModuleDialogFragment fmWidget = ((GenericWidgetAdapter) module.Adapter)
                                .getControlFragment();
                        if (fmWidget != null) {
                            fmWidget.setDataModule(module);
                            //
                            FragmentManager fm = getActivity().getSupportFragmentManager();
                            FragmentTransaction fragmentTransaction = fm.beginTransaction();
                            //
                            fragmentTransaction.add(fmWidget, "WIDGET");
                            fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                            fragmentTransaction.commit();
                        } else {
                            Intent acWidgetIntent = ((GenericWidgetAdapter) module.Adapter)
                                    .getControlActivityIntent(module);
                            if (acWidgetIntent != null) {
                                startActivity(acWidgetIntent);
                                getActivity().overridePendingTransition(R.anim.right_slide_in,
                                        R.anim.left_slide_out);
                            }
                        }
                    }

                }
            });
        } else {
            ((ModulesAdapter) lv.getAdapter()).notifyDataSetChanged();
        }
    }
}

From source file:com.github.runoshun.in_app_survey.ui.QuestionFragment.java

private void onMultiChoiceItemClick(MultiChoiceQuestion question, ListView listView, int position) {
    SparseBooleanArray checkedItems = listView.getCheckedItemPositions();
    List<Integer> selectedPositions = new ArrayList<>();

    int count = listView.getAdapter().getCount();
    for (int i = 0; i < count; ++i) {
        if (checkedItems.get(i)) {
            selectedPositions.add(i);/*from w w  w . j a va2s.c o m*/
        }
    }

    if (selectedPositions.size() > question.maxChoices) {
        listView.setItemChecked(position, false);
        selectedPositions.remove((Integer) position);
    }

    int[] selected = new int[selectedPositions.size()];
    for (int i = 0; i < selected.length; ++i) {
        selected[i] = selectedPositions.get(i);
    }

    if (selectedPositions.size() >= question.minChoices) {
        question.saveAnswer(selected);
    } else {
        question.saveAnswer(null);
    }
}

From source file:com.josecalles.tistiq.mvp.view.MainActivity.java

private void refreshContactList() {
    for (int j = 0, count = mNavigationView.getChildCount(); j < count; j++) {
        final View child = mNavigationView.getChildAt(j);
        if (child != null && child instanceof ListView) {
            final ListView menuView = (ListView) child;
            final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter();
            final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter();
            wrapped.notifyDataSetChanged();
        }//from   w  ww .  j  a  v a 2 s  .  co  m
    }
}

From source file:com.apotheosis.acceleration.monitor.MainMenuActivity.java

private void stopCollection() {
    if (collector != null) {
        collector.stop();/*from  w  w  w. j  ava 2  s.c o m*/
        collector = null;
        pauseAccel.setText("Start");

        if (getSupportActionBar() != null)
            getSupportActionBar().setTitle("Data Collection Not Running");
    }

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(R.string.app_name);

    ListView lv = (ListView) findViewById(R.id.fileList);
    ((FileListAdapter) lv.getAdapter()).refreshFiles();
}

From source file:com.armtimes.drawer.CommonFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    // Get current selected item.
    Cursor cursor = ((FragmentAdapter) l.getAdapter()).getCursor();
    cursor.moveToPosition(position);/*  w  w w .  jav  a 2 s  .  c  o m*/
    // Create new intent to send to News Reader Activity.
    Intent intent = new Intent(getActivity(), SingleArticlePreviewActivity.class);
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_CATEGORY_TITLE_ID, mCategoryTitleId);
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_TITLE,
            cursor.getString(cursor.getColumnIndexOrThrow(NewsContract.COL_NAME_NEWS_TITLE)));
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_DESCRIPTION,
            cursor.getString(cursor.getColumnIndexOrThrow(NewsContract.COL_NAME_NEWS_DESC_LONG)));
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_URL,
            cursor.getString(cursor.getColumnIndexOrThrow(NewsContract.COL_NAME_NEWS_URL)));
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_IMAGE_PATH,
            cursor.getString(cursor.getColumnIndexOrThrow(NewsContract.COL_NAME_NEWS_MAIN_IMAGE_PATH)));
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_IMAGE_LINK,
            cursor.getString(cursor.getColumnIndexOrThrow(NewsContract.COL_NAME_NEWS_IMAGE_URL)));
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_SHORT_DESC,
            cursor.getString(cursor.getColumnIndexOrThrow(NewsContract.COL_NAME_NEWS_DESC_SHORT)));
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_CATEGORY, mCategory);

    // Start News Reader Activity.
    startActivityForResult(intent, 0);
}

From source file:org.cvasilak.jboss.mobile.admin.fragments.ProfileViewFragment.java

@Override
public void onListItemClick(ListView list, View view, int position, long id) {
    MergeAdapter adapter = ((MergeAdapter) list.getAdapter());

    String selection;//from   w w w. j  a  v a2 s .  c o m

    Fragment fragment = null;

    if (position - 1 <= attributes.size()) { // Attribute selection
        selection = attributes.get(position - 1).getName();

        // TODO: show attributes screens
    } else if (position - 2 <= (attributes.size() + childTypes.size())) { // ChildType selection
        selection = childTypes.get(position - 2 - attributes.size()).getName();

        fragment = ChildResourcesViewFragment.newInstance(this.path, selection);

    } else { // Operation selection
        // TODO: show operations screen
    }

    // TODO: remove when all screens are implemented
    if (fragment == null)
        return;

    FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
    transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right,
            android.R.anim.slide_in_left, android.R.anim.slide_out_right);

    transaction.addToBackStack(null)
            .replace(android.R.id.content, fragment, fragment.getClass().getSimpleName()).commit();
}

From source file:net.kjmaster.cookiemom.action.scout.ActionScoutPickup.java

@Override
public void setupInnerViewElements(ViewGroup parent, View view) {
    super.setupInnerViewElements(parent, view); //To change body of overridden methods use File | Settings | File Templates.
    final ListView listView = (ListView) parent.findViewById(R.id.action_list);
    if (listView != null) {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override/*from w w  w .  ja va  2s  . c om*/
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Scout scout = (Scout) listView.getAdapter().getItem(i);
                ScoutPickupDialog scoutPickupDialog = new ScoutPickupDialog();
                scoutPickupDialog.ScoutPickupDialog(scout, mActivity, mFragment);

            }
        });
    }
}

From source file:com.google.samples.apps.friendlyping.fragment.FriendlyPingFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // Get the list view and set it up.
    ListView listView = (ListView) view.findViewById(R.id.ping_list);
    listView.setOnItemClickListener(mOnItemClickListener);
    listView.setEmptyView(view.findViewById(android.R.id.empty));
    if (listView.getAdapter() == null) {
        mPingerAdapter = new PingerAdapter(getActivity());
        listView.setAdapter(mPingerAdapter);
    }/* www. j a v  a 2  s .  co  m*/

    // Check for saved list of pingers.
    if (savedInstanceState == null) {
        // Start IntentService to register this application with GCM.
        Intent service = new Intent(getActivity(), RegistrationIntentService.class);
        getActivity().startService(service);
    } else {
        // If saved list of pingers exists use them.
        ArrayList<Pinger> tmpPingers = savedInstanceState.getParcelableArrayList(KEY_PINGERS);
        mPingerAdapter.addPinger(tmpPingers);
    }

    // Restore previously saved data.
    if (savedInstanceState != null) {
        ArrayList<Pinger> tmpPingers = savedInstanceState.getParcelableArrayList(KEY_PINGERS);
        if (tmpPingers != null) {
            mPingerAdapter = new PingerAdapter(view.getContext(), tmpPingers);
            listView.setAdapter(mPingerAdapter);
        }
    }

    final AppCompatActivity activity = (AppCompatActivity) getActivity();
    if (null != activity) {
        // Setting the status bar color and Toolbar as ActionBar requires API 21+.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            activity.setSupportActionBar((Toolbar) view.findViewById(R.id.toolbar_ping));
            //noinspection ConstantConditions
            activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
            activity.getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark));
        }
    }
    // [START show_ad]
    AdView adView = (AdView) view.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);
    // [END show_ad]
}

From source file:com.esri.android.maps.app.MapAppRobotiumTests.java

/**
 * Test searching with suggestions/*from www .  j a  v  a 2s.c o  m*/
 */
public void testSearchWithSuggestions() {
    // Get the map view
    View mapView = solo.getView(id.map);
    Assert.assertTrue(solo.waitForView(mapView));

    // Get the text field for inputting place names or addresses
    EditText editText = solo.getEditText(solo.getString(string.search), true);
    Assert.assertNotNull(editText);

    // Type in a few letters, assumes at
    // least one or more places nearby
    // using a value from your app settings.
    solo.typeText(editText, getActivity().getString(string.testPartialName));
    solo.sleep(4000);
    // Grab the list displaying the suggestions
    ListView listView = solo.getView(ListView.class, 0);
    Assert.assertNotNull(listView);
    // Assert there are at least 1  or more suggestions
    Assert.assertTrue(listView.getAdapter().getCount() > 0);
}