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:co.edu.uniajc.vtf.content.ListSitesFragment.java

@Override
public ListPointsAdapter getAdapter() {
    ListView loList = (ListView) this.getView().findViewById(R.id.lstPoints);
    return (ListPointsAdapter) loList.getAdapter();
}

From source file:org.mozilla.mozstumbler.client.serialize.KMLFragment.java

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    final ListView list = (ListView) v;
    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    final int position = info.position;
    final Object object = list.getAdapter().getItem(position);

    menu.add(R.string.load_file);// ww  w. j  a v  a 2 s . c  o  m
    menu.add(R.string.share_file);
    menu.add(R.string.delete_file);
    menu.add(R.string.delete_all);

    MenuItem.OnMenuItemClickListener listener = new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            contextItemSelected(item, (object == null) ? null : object.toString());
            if (mLoadFileDialog != null && mLoadFileDialog.isShowing()) {
                mLoadFileDialog.dismiss();
            }
            return false;
        }
    };

    for (int i = 0, n = menu.size(); i < n; i++)
        menu.getItem(i).setOnMenuItemClickListener(listener);
}

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

/**
 * Handles the selected item on the context menu. Could be an option to
 * delete the item or to get it from the moneybox.
 *//*from ww  w .  j  a  v a2 s  .c  o m*/
@Override
public boolean onContextItemSelected(MenuItem item) {
    int itemId;

    itemId = item.getItemId();
    if (itemId == CONTEXT_MENU_GET || itemId == CONTEXT_MENU_DELETE || itemId == CONTEXT_MENU_DROP) {

        AdapterView.AdapterContextMenuInfo info;
        ListView listView;
        Movement selected;

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

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

        switch (itemId) {
        case CONTEXT_MENU_GET:
            MovementsManager.getMovement(selected);
            ((IMoneyboxListener) getActivity()).onGetMovement(selected);
            break;

        case CONTEXT_MENU_DROP:
            MovementsManager.dropMovement(selected);
            break;

        case CONTEXT_MENU_DELETE:
            MovementsManager.deleteMovement(selected);
            ((IMoneyboxListener) getActivity()).onDeleteMovement(selected);
            break;
        }

        refresh();
    }

    return true;
}

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

protected void writeSelection(Intent intent) {
    ListView list = (ListView) findViewById(R.id.listView1);
    if (list.getCount() == 0)
        return;/* w w  w .  j a v  a2  s .com*/

    try {

        Object[] results = ((OptionListAdapter) list.getAdapter()).getCheckedValues();
        JSONObject obj = new JSONObject();

        JSONArray array = new JSONArray();

        if (null != results) {
            for (Object result : results)
                array.put(result.toString());
        }

        obj.put("selection", array);
        obj.put("key", selectKey);

        SharedPreferences sharedPref = getSharedPreferences(getString(R.string.preference_file_key),
                Context.MODE_PRIVATE);

        // android studio (0.5.1) decorates this line as an error (some
        // of the time, anyway) but it's not an error.

        String identifier = sharedPref.getString(getString(R.string.user_id_key), "");
        if (identifier.length() > 0)
            obj.put("user", identifier);

        String json = obj.toString(0);

        String outbound = "\u0002en";
        outbound += json;

        NdefRecord textRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, new byte[] { 'T' }, null,
                outbound.getBytes());

        NdefMessage message = new NdefMessage(new NdefRecord[] { textRecord });
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        Ndef ndef = Ndef.get(tag);
        ndef.connect();

        ndef.writeNdefMessage(message);
        ndef.close();

        Toast.makeText(this, R.string.write_ok, Toast.LENGTH_LONG).show();
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                finish();
            }
        }, 1500);

    } catch (Exception e) {

        Log.d(TAG, e.toString());
        String err = getString(R.string.tag_write_err) + "\n" + e.getMessage();
        Toast.makeText(this, err, Toast.LENGTH_LONG).show();
    }
}

From source file:de.damdi.fitness.activity.manage_workouts.WorkoutListFragment.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(((Workout) listView.getAdapter().getItem(position)));
}

From source file:org.mozilla.gecko.tests.AboutHomeTest.java

/**
 * Waits for the given ListView to have a non-empty adapter and be populated
 * with a minimum number of items./*www .  ja v  a 2  s .  co  m*/
 *
 * This method will return false if the given ListView or its adapter is null,
 * or if the ListView does not have the minimum number of items.
 */
protected boolean waitForListToLoad(final ListView listView, final int minSize) {
    Condition listWaitCondition = new Condition() {
        @Override
        public boolean isSatisfied() {
            if (listView == null) {
                return false;
            }

            final ListAdapter adapter = listView.getAdapter();
            if (adapter == null) {
                return false;
            }

            return (listView.getCount() - listView.getHeaderViewsCount() >= minSize);
        }
    };
    return waitForCondition(listWaitCondition, MAX_WAIT_MS);
}

From source file:org.bwgz.quotation.fragment.BookmarkAuthorsFragment.java

@Override
public void onCursorLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    Log.d(TAG,//  w  w w.  j  ava2s  . com
            String.format("onLoadFinished - loader: %s  cursor: %s (%d)", loader, cursor, cursor.getCount()));

    ListView listView = (ListView) getView().findViewById(R.id.list_view);
    TextView textView = (TextView) getView().findViewById(R.id.text_view);

    if (cursor.getCount() == 0) {
        listView.setVisibility(View.GONE);
        textView.setVisibility(View.VISIBLE);
    } else {
        listView.setVisibility(View.VISIBLE);
        textView.setVisibility(View.GONE);

        adapter = (AuthorPicksCursorAdapter) listView.getAdapter();
        if (adapter == null) {
            adapter = new AuthorPicksCursorAdapter(getView().getContext(), cursor,
                    R.layout.author_list_pick_view, getImageLoader());
            listView.setAdapter(adapter);
        } else {
            adapter.swapCursor(cursor);
        }
    }
}

From source file:com.fabernovel.alertevoirie.ExistingIncidentsActivity.java

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // Log.d(Constants.PROJECT_TAG, "onListItemClick : "+l.getAdapter().getItem(position));
    Intent i = new Intent(this, ReportDetailsActivity.class);
    i.putExtra("existing", true);
    i.putExtra("event", l.getAdapter().getItem(position).toString());

    try {/*w  w  w. j  a va  2 s  .  c o m*/
        Incident incident = Incident.fromJSONObject(this,
                new JSONObject(l.getAdapter().getItem(position).toString()));
        if (incident.state == 'R' || incident.invalidations > 0)
            return;
    } catch (JSONException e) {
        Log.e(Constants.PROJECT_TAG, "JSONException in onListItemClick", e);
    }
    startActivity(i);
    // super.onListItemClick(l, v, position, id);
}

From source file:org.bienvenidoainternet.app.MainActivity.java

public void refreshNavigator() {
    for (int i = 0, count = navigationView.getChildCount(); i < count; i++) {
        final View child = navigationView.getChildAt(i);
        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 w w .j  av a 2s . c om*/
    }
}

From source file:org.que.activities.fragments.CalendarBookedFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    String itemID = "NULL";
    Fragment frg = new Fragment();
    Bundle args = new Bundle();
    Object o = getListView().getItemAtPosition(position);
    super.onListItemClick(l, v, position, id);
    Cursor c = ((SimpleCursorAdapter) l.getAdapter()).getCursor();

    c.moveToPosition(position);//from www .  j  a  v  a  2  s .c om
    String description = c.getString(5); //gets the description field of the calendar item
    try {

        //check whether item is a session or a paper
        if (description.contains("session")) {
            //itemID cleans up the description String first to get the Database ID of the Session
            itemID = description
                    .replace(getActivity().getString(R.string.calendarEventDescription) + "sessionID", "");
            SessionEntity entity = ConferenceDAO.getSessionByID(itemID, getActivity());
            args.putSerializable(SessionFragment.ARG_SESSIONVIEW_FRAGMENT, entity);
            frg = new SessionFragment();

        } else if (description.contains("paper")) {
            itemID = description.replace(getActivity().getString(R.string.calendarEventDescription) + "paperID",
                    "");
            PaperEntity entity = new PaperEntity();
            entity = ConferenceDAO.getPaperByID(itemID, getActivity());
            args.putSerializable(PaperFragment.ARG_PAPERVIEW_FRAGMENT, entity);
            frg = new PaperFragment();

        }
    } catch (NullPointerException e) {
        AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
        b.setMessage(
                "Something went wrong when trying to retrieve this event. Please re-favorite the event to re-add it to the calendar.");
        b.setTitle("Oops");
        b.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        b.show();
    }
    if (frg != null) {
        frg.setArguments(args);
        FragmentManager mgr = ((FragmentActivity) getActivity()).getSupportFragmentManager();
        Fragment old = mgr.findFragmentById(R.id.content_frame);

        FragmentTransaction trx = mgr.beginTransaction();
        if (old != null)
            trx.remove(old);

        trx.add(R.id.content_frame, frg).addToBackStack(null) //TODO
                .commit();
    }
}