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:org.androidpn.demoapp.MessageListActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Intent intent = new Intent(this, MessageDetailActivity.class);
    Bundle bundle = new Bundle();
    bundle.putSerializable("message", (Serializable) parent.getAdapter().getItem(position));
    intent.putExtras(bundle);//from w  w  w . ja v a  2 s .  com
    ((SingleMessage) parent.getAdapter().getItem(position)).setStatus(1);
    ContentResolver contentResolver = getContentResolver();
    ContentValues contentValues = new ContentValues();
    contentValues.put(MESSAGE_SUMMARY_PROJECTION[6], 1);
    contentResolver.update(ServerMessage.CONTENT_URI, contentValues, "message_id = ?",
            new String[] { ((SingleMessage) parent.getAdapter().getItem(position)).getId() });
    mAdapter.notifyDataSetChanged();
    startActivity(intent);
}

From source file:com.agateau.equiv.ui.MealItemDetailActivity.java

private void setupTabs() {
    ListView fullListView = new ListView(this);
    ListView favoriteListView = new ListView(this);

    mFullListAdapter = new ProductListAdapter(this, mKernel, mProductStore.getItems());
    mFavoritesListAdapter = new ProductListAdapter(this, mKernel, mProductStore.getFavoriteItems());
    mProductStore.setOnProductStoreChangedListener(new ProductStore.OnProductStoreChangedListener() {
        @Override//from w w  w  .  ja  va 2 s  . com
        public void onFavoriteChanged() {
            mFavoritesListAdapter.notifyDataSetChanged();

            // Notify mFullListAdapter as well because it must update the state of its checkboxes
            mFullListAdapter.notifyDataSetChanged();
        }

        @Override
        public void onItemListChanged() {
            mFullListAdapter.notifyDataSetChanged();
        }
    });

    fullListView.setAdapter(mFullListAdapter);
    favoriteListView.setAdapter(mFavoritesListAdapter);

    AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Product product = (Product) parent.getAdapter().getItem(position);
            onSelectProduct(product);
        }
    };
    fullListView.setOnItemClickListener(listener);
    favoriteListView.setOnItemClickListener(listener);

    AdapterView.OnItemLongClickListener longClickListener = new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Product product = (Product) parent.getItemAtPosition(position);
            editCustomProduct(product);
            return true;
        }
    };

    fullListView.setLongClickable(true);
    favoriteListView.setLongClickable(true);

    fullListView.setOnItemLongClickListener(longClickListener);
    favoriteListView.setOnItemLongClickListener(longClickListener);

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    ActionBarViewTabBuilder builder = new ActionBarViewTabBuilder(actionBar, viewPager);
    builder.addTab(fullListView).setText(R.string.add_meal_item_tab_all);
    builder.addTab(favoriteListView).setText(R.string.add_meal_item_tab_favorites);
}

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

/**
 * Display a grid of all installed apps + virtual apps. Allow user to launch
 * apps.//  ww  w . ja v a  2s.c  o  m
 * 
 * @param context
 * @param applications
 */
public static void displayAllApps(final Launcher context, final ArrayList<ApplicationInfo> applications) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.apps_grid);

    final GridView gridView = (GridView) dialog.findViewById(R.id.grid);
    gridView.setAdapter(new AllItemAdapter(context, getApplications(context, applications, false)));
    gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ItemInfo itemInfo = (ItemInfo) parent.getAdapter().getItem(position);
            itemInfo.invoke(context);
            context.showCover(false);
            dialog.dismiss();
            if (itemInfo instanceof ApplicationInfo) {
                ApplicationInfo applicationInfo = (ApplicationInfo) itemInfo;
                RecentAppsTable.persistRecentApp(context, applicationInfo);
            }
        }

    });
    gridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> gridView, View view, int pos, long arg3) {
            ItemInfo itemInfo = (ItemInfo) gridView.getAdapter().getItem(pos);
            if (itemInfo instanceof ApplicationInfo) {
                Uri packageURI = Uri.parse("package:" + itemInfo.getIntent().getComponent().getPackageName());
                Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
                context.startActivity(uninstallIntent);
                context.showCover(false);
                dialog.dismiss();
                Analytics.logEvent(Analytics.UNINSTALL_APP);
            }

            return false;
        }

    });
    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_ALL_APPS);
}

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

/**
 * Display the list of browser bookmarks. Allow user to load bookmarked web
 * site./*from   w w w. ja  v a  2 s .co  m*/
 * 
 * @param context
 */
public static void displayBookmarks(final Launcher context) {
    final ArrayList<BookmarkInfo> bookmarks = loadBookmarks(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);
        Collections.sort(bookmarks, new Comparator<BookmarkInfo>() {

            @Override
            public int compare(BookmarkInfo lhs, BookmarkInfo rhs) {
                return lhs.getTitle().toLowerCase().compareTo(rhs.getTitle().toLowerCase());
            }

        });
        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_bookmarks));
    }
}

From source file:net.line2soft.preambul.controllers.ExcursionInfoListener.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    //Instruction click: display on map
    if (parent == activity.findViewById(R.id.listView1)) {
        MapController.getInstance(activity)
                .setPathToDisplay(activity.getIntent().getIntExtra(ExcursionListActivity.EXCURSION_ID, 0));
        MapController.getInstance(activity)
                .setInstructionToDisplay((int) parent.getAdapter().getItemId(position));
        launchMap(null);/*  ww  w. jav  a  2s  .  c om*/
    }
    //POI list item click : show item on map
    else if (parent == activity.findViewById(R.id.listView2)) {
        launchMap(((NamedPoint) parent.getItemAtPosition(position)).getPoint());
    }
}

From source file:com.andrasta.dashi.MainActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    prefs = new SharedPreferencesHelper(this);
    setupOrientation();//from w  w w  .  j  a  v  a  2s .  co  m
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ((DrawerLayout) findViewById(R.id.drawer)).openDrawer(Gravity.LEFT);
    laneView = (LaneView) findViewById(R.id.lane_view);
    polygonView = (PolygonView) findViewById(R.id.plate_frame);
    polygonView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            v.setVisibility(View.INVISIBLE);
        }
    });
    recognitionResult = (TextView) findViewById(R.id.recognition_result);
    recognitionResult.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            printResultsBuffer.reset();
            recognitionResult.setText("");
        }
    });
    textureView = (AutoFitTextureView) findViewById(R.id.texture);
    textureView.setSurfaceTextureListener(textureListener);
    textureView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            saveImageOnDisk.set(true);
        }
    });
    spinner = (Spinner) findViewById(R.id.camera_resolutions);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Size size = (Size) parent.getAdapter().getItem(position);
            if (!cameraRecSize.equals(size)) {
                cameraRecSize = size;
                updatePolygonView();
                camera.close();
                alprHandler.stop();
                openCamera(textureView.getWidth(), textureView.getHeight());
                alprHandler.start();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    display = getWindowManager().getDefaultDisplay();
    licensePlateMatcher = LicensePlateMatcher.getInstance(prefs);
    File configDir = new File(prefs.getString(KEY_ALPR_CONFIG_DIR, null));
    alprHandler = new ImageHandler(configDir, imageHandlerCallback, new Handler());
    camera = new Camera(this, this);
    createCameraSizesAdapter();
    try {
        locationHelper.start(this);
    } catch (IOException ioe) {
        Log.d(TAG, "Cannot start location", ioe);
    }
}

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

/**
 * Change the order of the favorite rows.
 * // w  w w .ja  va 2  s. co  m
 * @param context
 */
public static void displayChangeRowOrder(final Launcher context) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.row_list);

    final ListView listView = (ListView) dialog.findViewById(R.id.rowList);
    ArrayList<RowInfo> persistedRows = RowsTable.getRows(context);
    final ArrayList<RowInfo> rows = new ArrayList<RowInfo>();
    // Add in reverse order to match favorite rows order
    for (RowInfo rowInfo : persistedRows) {
        rows.add(0, rowInfo);
    }
    final RowAdapter rowAdapter = new RowAdapter(context, rows);
    listView.setAdapter(rowAdapter);
    listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            RowInfo rowInfo = (RowInfo) parent.getAdapter().getItem(position);
            if (rowInfo.isSelected()) {
                rowInfo.setSelected(false);

                // Persist the new row order
                try {
                    int counter = 0;
                    for (int i = rowAdapter.getCount() - 1; i >= 0; i--) {
                        RowInfo currentRowInfo = (RowInfo) parent.getAdapter().getItem(i);
                        RowsTable.updateRow(context, currentRowInfo.getId(), currentRowInfo.getTitle(), counter,
                                currentRowInfo.getType());
                        counter++;
                    }
                } catch (Exception e) {
                    Log.e(LOG_TAG, "displayChangeRowOrder", e);
                }
                Analytics.logEvent(Analytics.CHANGE_ROW_ORDER);
            } else {
                rowInfo.setSelected(true);
            }
            rowAdapter.notifyDataSetChanged();
        }

    });
    listView.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // Swap the selected item in the list
            int selectedRowIndex = -1;
            for (int i = 0; i < rows.size(); i++) {
                RowInfo rowInfo = rows.get(i);
                if (rowInfo.isSelected()) {
                    selectedRowIndex = i;
                    break;
                }
            }
            if (selectedRowIndex != -1) {
                try {
                    Collections.swap(rows, position, selectedRowIndex);
                    rowAdapter.notifyDataSetChanged();
                } catch (Exception e) {
                    Log.e(LOG_TAG, "displayChangeRowOrder", e);
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }

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

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

    });
    Button okButton = (Button) dialog.findViewById(R.id.okButton);
    okButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            context.showCover(false);
            dialog.dismiss();
            context.reloadAllGalleries();
        }

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

From source file:org.dmfs.tasks.SettingsListFragment.java

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long rowId) {
    VisibleListAdapter adapter = (VisibleListAdapter) adapterView.getAdapter();
    VisibleListAdapter.CheckableItem item = (VisibleListAdapter.CheckableItem) view.getTag();
    boolean checked = item.coloredCheckBox.isChecked();
    item.coloredCheckBox.setChecked(!checked);
    adapter.addToState(rowId, !checked);
}

From source file:com.android.settings.users.EditUserPhotoController.java

private void showUpdatePhotoPopup() {
    final boolean canTakePhoto = canTakePhoto();
    final boolean canChoosePhoto = canChoosePhoto();

    if (!canTakePhoto && !canChoosePhoto) {
        return;/*  www .jav a  2s.co  m*/
    }

    final Context context = mImageView.getContext();
    final List<EditUserPhotoController.RestrictedMenuItem> items = new ArrayList<>();

    if (canTakePhoto) {
        final String title = context.getString(R.string.user_image_take_photo);
        final Runnable action = new Runnable() {
            @Override
            public void run() {
                takePhoto();
            }
        };
        items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action));
    }

    if (canChoosePhoto) {
        final String title = context.getString(R.string.user_image_choose_photo);
        final Runnable action = new Runnable() {
            @Override
            public void run() {
                choosePhoto();
            }
        };
        items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action));
    }

    final ListPopupWindow listPopupWindow = new ListPopupWindow(context);

    listPopupWindow.setAnchorView(mImageView);
    listPopupWindow.setModal(true);
    listPopupWindow.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
    listPopupWindow.setAdapter(new RestrictedPopupMenuAdapter(context, items));

    final int width = Math.max(mImageView.getWidth(),
            context.getResources().getDimensionPixelSize(R.dimen.update_user_photo_popup_min_width));
    listPopupWindow.setWidth(width);
    listPopupWindow.setDropDownGravity(Gravity.START);

    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listPopupWindow.dismiss();
            final RestrictedMenuItem item = (RestrictedMenuItem) parent.getAdapter().getItem(position);
            item.doAction();
        }
    });

    listPopupWindow.show();
}