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:com.granita.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.cb.isChecked();
    item.cb.setChecked(!checked);//from w  w  w.j a  va 2  s  . c o m
    adapter.addToState(rowId, !checked);
}

From source file:org.bwgz.quotation.activity.SearchResultsActivity.java

private void handleIntent(final Intent intent) {
    Log.d(TAG, String.format("handleIntent - intent: %s", intent));

    String query = intent.getStringExtra(SearchManager.QUERY);
    int type = intent.getIntExtra(SearchResultsActivity.EXTRA_SEARCH_TYPE, FreebaseSearch.SEARCH_TYPE_KEYWORD);

    getTracker().send(MapBuilder.createEvent("ui.search", getSearchType(type), query, null).build());

    searchResultsAdapter = new SearchResultsAdapter(this, R.layout.quotation_pick_view, new ArrayList<Pick>(),
            this, getImageLoader());
    loadSearchResultsTask = (SearchResultsTask) new SearchResultsTask(this, searchResultsAdapter, 0,
            DEFAULT_LIMIT).execute(intent);

    ListView listView = (ListView) findViewById(R.id.result_list);
    listView.setAdapter(searchResultsAdapter);

    listView.setOnScrollListener(new OnScrollListener() {
        @Override//from w  w  w .jav  a  2  s.  c om
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            Log.d(TAG, String.format(
                    "onScroll - view %s  firstVisibleItem: %d  visibleItemCount: %d  totalItemCount: %d", view,
                    firstVisibleItem, visibleItemCount, totalItemCount));
            if ((loadSearchResultsTask.getStatus() == AsyncTask.Status.FINISHED)
                    && (totalItemCount < searchResultsAdapter.getHits())
                    && (firstVisibleItem + visibleItemCount == totalItemCount)) {
                Log.d(TAG, "Load Next Page!");

                loadSearchResultsTask = (SearchResultsTask) new SearchResultsTask(SearchResultsActivity.this,
                        searchResultsAdapter, totalItemCount, Math.max(visibleItemCount, DEFAULT_LIMIT))
                                .execute(intent);
            }
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    });

    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            SearchResultsAdapter adapter = (SearchResultsAdapter) parent.getAdapter();

            List<String> mids = new ArrayList<String>();
            for (int i = 0; i < adapter.getCount(); i++) {
                Pick pick = (Pick) adapter.getItem(i);
                mids.add(pick.getId());
            }

            Intent intent = new Intent(getApplicationContext(), QuotationActivity.class);
            intent.putExtra(QuotationActivity.EXTRA_IDS, mids.toArray(new String[mids.size()]));
            intent.putExtra(QuotationActivity.EXTRA_POSITION, position);
            startActivity(intent);
        }
    });

}

From source file:vn.cybersoft.obs.android.fragments.MainMenuFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Activity activity = getActivity();/*from w w w  . j a  v a2s . co m*/

    if (null == activity) {
        return;
    }

    if (activity instanceof MainActivity) {
        MainMenuItemAdapter adapter = (MainMenuItemAdapter) parent.getAdapter();
        switch (adapter.getItem(position).id) {
        case MENU_BATTERY_INFO:
            ((MainActivity) activity).swapToFragmentView(ScreenList.BATTERY_INFO);
            break;
        case MENU_OPTIMIZATION:
            ((MainActivity) activity).swapToFragmentView(ScreenList.OPTIMIZATION);
            break;

        /*         case MENU_CHARGE:
                    ((MainActivity)activity).swapToFragmentView(ScreenList.CHARGE);
                    break;*/

        case MENU_CONSUMPTION:
            ((MainActivity) activity).swapToFragmentView(ScreenList.CONSUMPTION);
            break;

        case MENU_ABOUT:
            ((MainActivity) activity).swapToFragmentView(ScreenList.ABOUT);
            break;
        }
        ((SlidingFragmentActivity) activity).getSlidingMenu().showContent();
    }

}

From source file:org.mifos.androidclient.main.CollectionSheetActivity.java

@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long rowId) {
    CollectionSheetCustomer group = (CollectionSheetCustomer) adapterView.getAdapter().getItem(position);
    CollectionSheetHolder.setCurrentCustomer(group);
    Intent intent = new Intent().setClass(this, CollectionSheetCustomerActivity.class);
    intent.putExtra(CollectionSheetCustomer.BUNDLE_KEY, group);
    startActivity(intent);//from   w  w  w .j a  v  a2 s  . c o m
    return true;
}

From source file:com.learnNcode.mediachooser.fragment.ImageFragment.java

private void setAdapter(Cursor imagecursor) {
    mGalleryModelList = new ArrayList<MediaModel>();

    for (int i = 0; i < imagecursor.getCount(); i++) {
        imagecursor.moveToPosition(i);/*from  w w w .ja v  a  2 s  .c  o  m*/
        int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
        MediaModel galleryModel = new MediaModel(imagecursor.getString(dataColumnIndex).toString(), false);
        mGalleryModelList.add(galleryModel);
    }

    mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false);
    mImageGridView.setAdapter(mImageAdapter);

    mImageGridView.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 ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)
                    && (!galleryModel.status)) {

                Toast.makeText(getActivity(),
                        getActivity().getResources().getString(R.string.max_limit_reach_error),
                        Toast.LENGTH_SHORT).show();

            } else {

                // inverse the status
                galleryModel.status = !galleryModel.status;

                adapter.notifyDataSetChanged();

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

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

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

From source file:com.josenaves.sunshine.app.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // The SimpleCursorAdapter will take data from the database through the
    // Loader and use it to populate the ListView it's attached to.
    mForecastAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_forecast, null,
            // the column names to use to fill the textviews
            new String[] { WeatherContract.WeatherEntry.COLUMN_DATETEXT,
                    WeatherContract.WeatherEntry.COLUMN_SHORT_DESC,
                    WeatherContract.WeatherEntry.COLUMN_MAX_TEMP,
                    WeatherContract.WeatherEntry.COLUMN_MIN_TEMP },
            // the textviews to fill with the data pulled from the columns above
            new int[] { R.id.list_item_date_textview, R.id.list_item_forecast_textview,
                    R.id.list_item_high_textview, R.id.list_item_low_textview },
            0);/*from w ww .  j  a  v a2  s .c  o m*/

    mForecastAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            boolean isMetric = Utility.isMetric(getActivity());
            switch (columnIndex) {
            case COL_WEATHER_MAX_TEMP:
            case COL_WEATHER_MIN_TEMP: {
                // we have to do some formatting and possibly a conversion
                ((TextView) view).setText(Utility.formatTemperature(cursor.getDouble(columnIndex), isMetric));
                return true;
            }
            case COL_WEATHER_DATE: {
                String dateString = cursor.getString(columnIndex);
                TextView dateView = (TextView) view;
                dateView.setText(Utility.formatDate(dateString));
                return true;
            }
            }
            return false;
        }
    });

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            SimpleCursorAdapter adapter = (SimpleCursorAdapter) adapterView.getAdapter();
            Cursor cursor = adapter.getCursor();
            if (cursor != null && cursor.moveToPosition(position)) {
                String dateString = Utility.formatDate(cursor.getString(COL_WEATHER_DATE));
                String weatherDescription = cursor.getString(COL_WEATHER_DESC);

                boolean isMetric = Utility.isMetric(getActivity());
                String high = Utility.formatTemperature(cursor.getDouble(COL_WEATHER_MAX_TEMP), isMetric);
                String low = Utility.formatTemperature(cursor.getDouble(COL_WEATHER_MIN_TEMP), isMetric);

                String detailString = String.format("%s - %s - %s/%s", dateString, weatherDescription, high,
                        low);

                Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                        detailString);
                startActivity(intent);
            }
        }
    });

    return rootView;
}

From source file:com.zzx.photo.ImageFragment.java

private void setAdapter(Cursor imagecursor) {

    if (imagecursor.getCount() > 0) {
        ///storage/sdcard0/Toast/download/T1bRVvBCWv1RXrhCrK_l.jpg
        ///storage/sdcard1/Toast/download/4_1.png
        mGalleryModelList = new ArrayList<MediaModel>();
        for (int i = 0; i < imagecursor.getCount(); i++) {
            imagecursor.moveToPosition(i);
            int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
            int nameColumuIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME);
            String url = imagecursor.getString(dataColumnIndex).toString();
            String name = imagecursor.getString(nameColumuIndex);
            MediaModel galleryModel = new MediaModel(url, false, name);
            mGalleryModelList.add(galleryModel);
            mUrlList.add(url);/*from   ww  w .  ja v  a2s  . c  o  m*/
        }

        mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false);
        mImageGridView.setAdapter(mImageAdapter);
    } else {
        Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                Toast.LENGTH_SHORT).show();
    }

    mImageGridView.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);

            String nameString = mUrlList.get(position);
            Intent intent = new Intent(getActivity(), ViewPagerActivity.class);
            intent.putExtra("imageurl", mUrlList);
            intent.putExtra("currentPosition", position);
            startActivity(intent);

            // inverse the status
            galleryModel.status = !galleryModel.status;

            adapter.notifyDataSetChanged();

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

        }
    });
}

From source file:it.uniroma2.foundme.studente.RegistrationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registration);
    context = this;
    btSignUp = (Button) findViewById(R.id.btSignUp);

    etNewUser = (EditText) findViewById(R.id.etNewUser);
    etNewPass1 = (EditText) findViewById(R.id.etNewPass);
    etNewPass2 = (EditText) findViewById(R.id.etNewPass2);
    etNewMail = (EditText) findViewById(R.id.etNewMail);
    etNewMail2 = (EditText) findViewById(R.id.etNewMail2);
    etNewId = (EditText) findViewById(R.id.etNewId);
    spDept = (Spinner) findViewById(R.id.spDept);

    final ArrayAdapter<CharSequence> adapter = createFromResource(this, R.array.Departments,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spDept.setAdapter(adapter);//w  w  w . j av a2 s. com

    spDept.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        protected Adapter initializedAdapter = null;

        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            if (initializedAdapter != parentView.getAdapter()) {
                initializedAdapter = parentView.getAdapter();
                return;
            }

            Dept = parentView.getItemAtPosition(position).toString();

        }

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

    btSignUp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            NewUser = etNewUser.getText().toString();
            NewPass1 = etNewPass1.getText().toString();
            NewPass2 = etNewPass2.getText().toString();
            NewMail = etNewMail.getText().toString();
            NewMail2 = etNewMail2.getText().toString();
            NewId = etNewId.getText().toString();

            if (checkPlayServices()) {
                gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
                if (!checkLoginData(NewPass1, NewPass2, NewMail, NewMail2, Dept)) {
                    Toast.makeText(getApplicationContext(), Variables_it.FILL_FIELD, Toast.LENGTH_LONG).show();
                } else {
                    try {
                        manageRegistration(NewUser, NewPass1, NewMail, NewId, Dept);
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    });

}

From source file:jupiter.broadcasting.live.tv.EpisodeListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    getActivity().setProgressBarIndeterminateVisibility(true);

    v = inflater.inflate(R.layout.episodelist_fragment, null);

    FragmentManager fm = getActivity().getSupportFragmentManager();
    ft = fm.beginTransaction();/*from ww  w  .  jav a  2 s  .  c  o  m*/
    if (mFragment1 == null) {
        mFragment1 = new MenuBarFragment();
        ft.add(mFragment1, "mf");
    }
    ft.commit();
    mFragment1.setHasOptionsMenu(true);
    mFragment1.setMenuVisibility(false);

    opId = 555;
    asyncResultView = (ListView) v.findViewById(R.id.episodelist);
    asyncResultView.setOnScrollListener(new EndlessScrollListener());
    asyncResultView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            long d = id;
            aurls = arssLinkTable.get(parent.getAdapter().getItem(position));
            vurls = vrssLinkTable.get(parent.getAdapter().getItem(position));
            title = (String) parent.getAdapter().getItem(position);
            //mMode = getActivity().startSupportActionMode(new EpisodeActionMode());
            //actionmode replaced by menufragment, just show or hide

            if (mFragment1.isMenuVisible() && opId == position) {
                mFragment1.setMenuVisibility(false);
            } else {
                mFragment1.setMenuVisibility(true);
                opId = position;
            }
        }
    });

    Bundle b = getArguments();
    afeed = b.getString("SHOW_AUDIO");
    vfeed = b.getString("SHOW_VIDEO");
    first = true;
    RSS_parse newparse = new RSS_parse(); //do networking in async task SDK>9
    newparse.execute(afeed, vfeed, "0");

    return v;
}

From source file:de.skubware.opentraining.activity.create_workout.DialogWorkoutOverviewFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    final View v = inflater.inflate(R.layout.fragment_dialog_workout_overview, null);

    mEditTextWorkoutName = (EditText) v.findViewById(R.id.edittext_workout_name);
    mEditTextWorkoutName.setText(mWorkout.getName());

    mListView = (ListView) v.findViewById(R.id.listview);
    mListView.setAdapter(new ArrayAdapter<FitnessExercise>(getActivity(), android.R.layout.simple_list_item_1,
            android.R.id.text1, mWorkout.getFitnessExercises()));
    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override/* w w  w .  j a v a2  s  .  c  o m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final FitnessExercise fEx = (FitnessExercise) parent.getAdapter().getItem(position);

            new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.are_you_sure))
                    .setMessage(
                            getString(R.string.really_remove_exercise).replace("EXERCISE_NAME", fEx.toString()))
                    .setPositiveButton(getString(android.R.string.ok), new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            removeExerciseFromWorkout(fEx);
                            dialog.dismiss();
                        }

                    }).setNegativeButton(getString(R.string.cancel), new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).create().show();
        }
    });

    return new AlertDialog.Builder(getActivity()).setTitle(mWorkout.getName()).setView(v).setCancelable(true)
            .setPositiveButton(getString(R.string.save_workout), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // check if name is empty
                    final String workoutName = mEditTextWorkoutName.getText().toString();
                    if (workoutName.equals("") || workoutName.replaceAll(" ", "").equals("")) {
                        Toast.makeText(getActivity(), getString(R.string.workout_name_cannot_be_empty),
                                Toast.LENGTH_LONG).show();
                        return;
                    }

                    // check if file already exists
                    if (fileAlreadyExists(workoutName)) {
                        showOverrideDialog();
                        return;
                    }

                    saveWorkout(getActivity());
                }
            }).setNegativeButton(getString(R.string.discard), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finishActivities(getActivity());
                }
            }).create();
}