Example usage for android.widget AdapterView getAdapter

List of usage examples for android.widget AdapterView getAdapter

Introduction

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

Prototype

public abstract T getAdapter();

Source Link

Document

Returns the adapter currently associated with this widget.

Usage

From source file:tw.idv.palatis.danboorugallery.PostListActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Object rawitem = parent.getAdapter().getItem(position);
    if (rawitem.getClass().equals(DrawerListAdapter.DrawerItem.class)) {
        DrawerListAdapter.DrawerItem item = (DrawerListAdapter.DrawerItem) rawitem;
        switch (item.id) {
        case R.id.action_new_host:
            startActivity(new Intent(parent.getContext(), NewHostActivity.class));
            break;
        }//from  w w w .ja va 2s.  c o  m
        mDrawerLayout.closeDrawer(mDrawerLeft);
    } else if (rawitem instanceof Cursor) {
        Cursor cursor = (Cursor) rawitem;
        int host_id = cursor.getInt(HostsTable.INDEX_HOST_DATABASE_ID);
        Host host = SiteSession.getHostById(host_id);
        host.enabled = !host.enabled;
        HostsTable.addOrUpdateHost(host);
    }
}

From source file:dynamite.zafroshops.app.fragment.TypedZopsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_typed_zops, container, false);

    ListView listView = (ListView) rootView.findViewById(R.id.listViewZops);

    resetVisibility(listView, (LinearLayout) rootView.findViewById(R.id.noZops),
            (RelativeLayout) rootView.findViewById(R.id.relativeLayoutLoader), force);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from  ww w  . j a v a2  s .  c  om*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            MobileZop item = (MobileZop) parent.getAdapter().getItem(position);
            MainActivity activity = (MainActivity) getActivity();

            if (activity.AdsActive && activity.Interstitial.isLoaded()) {
                activity.Interstitial.show();
            }
            activity.setCurrentItem(item.id, item);
            activity.nextMenu(ZopItemFragment.newInstance(item.id), true, 100);
        }
    });

    listView.setAdapter(adapter);

    return rootView;
}

From source file:com.example.de.taomi2.mediachooser.fragment.VideoFragment.java

private void setAdapter() {
    int count = mCursor.getCount();

    if (count > 0) {
        mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA);

        //move position to first element
        mCursor.moveToFirst();/*from w ww.  jav  a2 s  . c o  m*/

        mGalleryModelList = new ArrayList<MediaModel>();
        for (int i = 0; i < count; i++) {
            mCursor.moveToPosition(i);
            String url = mCursor.getString(mDataColumnIndex);
            mGalleryModelList.add(new MediaModel(url, false));
        }

        mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true);
        mVideoAdapter.videoFragment = this;
        mVideoGridView.setAdapter(mVideoAdapter);
        mVideoGridView.setOnScrollListener(this);
    } else {
        Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                Toast.LENGTH_SHORT).show();

    }

    mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);
            File file = new File(galleryModel.url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "video/*");
            startActivity(intent);
            return false;
        }
    });

    mVideoGridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // update the mStatus of each category in the adapter
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);

            if (!galleryModel.status) {
                long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()),
                        true);
                if (size != 0) {
                    Toast.makeText(getActivity(),
                            getActivity().getResources().getString(R.string.file_size_exeeded) + "  "
                                    + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " "
                                    + getActivity().getResources().getString(R.string.mb),
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                /*
                if((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)){
                if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) {
                 Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + "  " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show();
                 return;
                } else {
                 Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + "  " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show();
                 return;
                }
                }
                */
            }
            /*
            // inverse the status
            galleryModel.status = ! galleryModel.status;
            adapter.notifyDataSetChanged();
            */
            int i = 0;
            for (; i < adapter.getCount(); i++) {
                if (i != position) {
                    adapter.getItem(i).status = false;
                }
            }
            galleryModel.status = !galleryModel.status;
            adapter.notifyDataSetChanged();
            mSelectedItems.clear();
            if (galleryModel.status) {
                mSelectedItems.add(galleryModel.url.toString());
                //MediaChooserConstants.SELECTED_MEDIA_COUNT ++;

            } else {
                /*
                mSelectedItems.remove(galleryModel.url.toString().trim());
                MediaChooserConstants.SELECTED_MEDIA_COUNT --;
                */
            }

            if (mCallback != null) {
                mCallback.onVideoSelected(mSelectedItems.size());
                Intent intent = new Intent();
                intent.putStringArrayListExtra("list", mSelectedItems);
                getActivity().setResult(Activity.RESULT_OK, intent);
            }

        }
    });

}

From source file:mx.itesm.logistics.crew_tracking.fragment.ShopListFragment.java

@Override
public void onItemClick(AdapterView adapterView, View view, int position, long id) {
    mShop = (Shop) adapterView.getAdapter().getItem(position);
    launchNewDelivery();//  www  .  ja  va 2  s .  c om
}

From source file:com.nicolls.ablum.fragment.VideoFragment.java

private void setAdapter() {
    int count = mCursor.getCount();
    //      Toast.makeText(getActivity(),pathList.size()+"###",Toast.LENGTH_SHORT).show();

    if (count > 0) {
        mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA);

        //move position to first element
        mCursor.moveToFirst();//from  www .jav a  2 s  .c  o m

        mGalleryModelList = new ArrayList<MediaModel>();
        for (int i = 0; i < count; i++) {
            mCursor.moveToPosition(i);
            String url = mCursor.getString(mDataColumnIndex);
            MediaModel galleryModel = new MediaModel(url, false);
            for (String path : pathList) {
                if (TextUtils.equals(path, galleryModel.url)) {
                    galleryModel.status = true;
                    mSelectedItems.add(galleryModel.url.toString());
                    break;
                }
            }

            mGalleryModelList.add(galleryModel);
        }

        mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true);
        mVideoAdapter.videoFragment = this;
        mVideoGridView.setAdapter(mVideoAdapter);
        mVideoGridView.setOnScrollListener(this);
    } else {
        Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                Toast.LENGTH_SHORT).show();

    }

    mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);
            File file = new File(galleryModel.url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "video/*");
            startActivity(intent);
            return false;
        }
    });

    mVideoGridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // update the mStatus of each category in the adapter
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);

            if (!galleryModel.status) {
                long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()),
                        true);
                if (size != 0) {
                    Toast.makeText(getActivity(),
                            getActivity().getResources().getString(R.string.file_size_exeeded) + "  "
                                    + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " "
                                    + getActivity().getResources().getString(R.string.mb),
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) {
                    if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.file),
                                Toast.LENGTH_SHORT).show();
                        return;
                    } else {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.files),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                }
            }

            // inverse the status
            galleryModel.status = !galleryModel.status;
            adapter.notifyDataSetChanged();

            if (galleryModel.status) {
                mSelectedItems.add(galleryModel.url.toString());
                MediaChooserConstants.SELECTED_MEDIA_COUNT++;

            } else {
                mSelectedItems.remove(galleryModel.url.toString().trim());
                MediaChooserConstants.SELECTED_MEDIA_COUNT--;
            }

            if (mCallback != null) {
                mCallback.onVideoSelected(mSelectedItems.size());
                Intent intent = new Intent();
                intent.putStringArrayListExtra("list", mSelectedItems);
                getActivity().setResult(Activity.RESULT_OK, intent);
            }

        }
    });

}

From source file:tw.idv.palatis.danboorugallery.PostListActivity.java

@Override
public boolean onItemLongClick(final AdapterView<?> parent, View view, int position, long id) {
    Object item = parent.getAdapter().getItem(position);
    if (item instanceof Cursor) {
        final Cursor cursor = (Cursor) item;
        final int host_id = cursor.getInt(HostsTable.INDEX_HOST_DATABASE_ID);
        PopupMenu popup = new PopupMenu(PostListActivity.this, view);
        popup.inflate(R.menu.popupmenu_host_item);
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override/*www .  ja v a2s  .com*/
            public boolean onMenuItemClick(MenuItem menuItem) {
                final Host host = SiteSession.getHostById(host_id);
                int id = menuItem.getItemId();
                switch (id) {
                case R.id.popupmenu_host_item_edit:
                    Intent intent = new Intent(PostListActivity.this, NewHostActivity.class);
                    intent.putExtra(Host.TABLE_NAME + Host.KEY_HOST_DATABASE_ID, host.id);
                    startActivity(intent);
                    return true;
                case R.id.popupmenu_host_item_delete:
                    AlertDialog.Builder b = new AlertDialog.Builder(PostListActivity.this);
                    b.setTitle(R.string.dialog_delete_host_title);
                    b.setMessage(getResources().getString(R.string.dialog_delete_host_message, host.name,
                            host.url, host.getLogin(), host.getAPI().getName()));
                    b.setIcon(android.R.drawable.ic_dialog_alert);
                    b.setNegativeButton(android.R.string.cancel, null);
                    b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            HostsTable.removeHost(host);
                        }
                    });
                    b.create().show();
                    return true;
                }
                return false;
            }
        });
        popup.setForceShowIcon(true);
        popup.show();
        return true;
    }
    return false;
}

From source file:com.raza.betternts.activities.TabFragment1.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.tab_fragment, container, false);
    lvPosts = (ListView) view.findViewById(R.id.lv_posts);
    srLayout = (SwipeRefreshLayout) view.findViewById(R.id.tab_fragment);

    fillData();/* www .  j a v  a 2s. co m*/

    {
        lvPosts.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(final AdapterView<?> parent, View view, final int position, long id) {
                /**
                 * This is magic right here wow, thanks stackexchange
                 */
                final Cursor c = (Cursor) parent.getAdapter().getItem(position);
                String name = c.getString(c.getColumnIndex(DbSchema.COL_NAME));
                //Show dialog for choices
                AlertDialog.Builder inputDialog = new AlertDialog.Builder(getContext());
                inputDialog.setTitle(name).setItems(list, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        menuOption(c, which);
                    }
                });
                inputDialog.show();
            }
        });
        lvPosts.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
                /**
                 * This is magic right here wow, thanks stackexchange
                 */
                final Cursor c = (Cursor) parent.getAdapter().getItem(position);
                String name = c.getString(c.getColumnIndex(DbSchema.COL_NAME));
                //Show dialog for choices
                AlertDialog.Builder inputDialog = new AlertDialog.Builder(getContext());
                inputDialog.setTitle(name).setItems(list, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        menuOption(c, which);
                    }
                });
                inputDialog.show();
                return true;
            }
        });
    }
    {
        srLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                refresh();
            }
        });
    }

    return view;
}

From source file:org.mythdroid.activities.Main.java

private Dialog createWakeDialog() {

    final AlertDialog d = new AlertDialog.Builder(ctx).setItems(new String[] {}, null)
            .setIcon(drawable.ic_lock_power_off).setTitle(R.string.wakeFe).create();

    d.getListView().setOnItemClickListener(new OnItemClickListener() {
        @Override//w ww  . j  av  a2  s.  co  m
        public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
            String name = (String) av.getAdapter().getItem(pos);
            try {
                WakeOnLan.wake(DatabaseUtil.getFrontendHwAddr(ctx, name));
                Globals.curFe = name;
            } catch (Exception e) {
                ErrUtil.err(ctx, e);
            }
            d.dismiss();
        }
    });

    return d;

}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Display the list of Spotlight web apps:
 * https://www.google.com/tv/spotlight-gallery.html Allow the user to launch
 * a web app in the browser.// w  ww  .  j  a va 2  s .c om
 * 
 * @param context
 */
public static void displayAllSpotlight(final Launcher context) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.spotlight_grid);

    final GridView gridView = (GridView) dialog.findViewById(R.id.grid);
    final ArrayList<SpotlightInfo> spotlights = SpotlightTable.getAllSpotlights(context);
    gridView.setAdapter(new AllSpotlightAdapter(context, spotlights));
    gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            SpotlightInfo spotlightInfo = (SpotlightInfo) parent.getAdapter().getItem(position);
            spotlightInfo.invoke(context);
            context.showCover(false);
            dialog.dismiss();
            Analytics.logEvent(Analytics.INVOKE_SPOTLIGHT_WEB_APP);
        }

    });
    gridView.setDrawingCacheEnabled(true);
    gridView.setOnKeyListener(onKeyListener);
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_SPOTLIGHT_WEB_APPS);
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Display the list of browser history.//from w w  w . j a v  a  2s.co m
 * 
 * @param context
 */
public static void displayBrowserHistory(final Launcher context) {
    final ArrayList<BookmarkInfo> bookmarks = loadBrowserHistory(context);
    if (bookmarks.size() > 0) {
        final Dialog dialog = new Dialog(context);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.bookmarks_list);

        ListView listView = (ListView) dialog.findViewById(R.id.list);
        listView.setAdapter(new BookmarkAdapter(context, bookmarks));
        listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                BookmarkInfo bookmark = (BookmarkInfo) parent.getAdapter().getItem(position);
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(bookmark.getUrl()));
                context.startActivity(browserIntent);
                context.showCover(false);
                dialog.dismiss();
                Analytics.logEvent(Analytics.INVOKE_BOOKMARK);
            }

        });
        listView.setDrawingCacheEnabled(true);
        listView.setOnKeyListener(onKeyListener);
        dialog.setOnDismissListener(new OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
                context.showCover(false);
            }

        });
        context.showCover(true);
        dialog.show();
        Analytics.logEvent(Analytics.DIALOG_BOOKMARKS);
    } else {
        displayAlert(context, context.getString(R.string.dialog_no_browser_history));
    }
}