Example usage for android.widget AbsListView setAdapter

List of usage examples for android.widget AbsListView setAdapter

Introduction

In this page you can find the example usage for android.widget AbsListView setAdapter.

Prototype

@Override
public void setAdapter(ListAdapter adapter) 

Source Link

Usage

From source file:com.concavenp.nanodegree.popularmovies.MovieListingFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Set the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_movieitem_grid, container, false);

    // Create the grid of views who's content will be driven by the adapter
    AbsListView gridView = (GridView) view.findViewById(R.id.main_Movies_GridView);
    mAdapter = new MovieAdapter(getActivity(), R.id.main_Movies_GridView, new MovieItems());
    gridView.setAdapter(mAdapter);

    // Instantiate the RequestQueue.
    mRequestQueue = Volley.newRequestQueue(getActivity());

    // Get the sort type that should be used when requesting data from the movie DB
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    mSortOrder = prefs.getString(getResources().getString(R.string.sorting_preference_type_key),
            getResources().getString(R.string.default_sorting_preference_value));

    // Make the web request for data
    requestData();//from   w  w w.  j  a va2 s .  c  om

    return view;
}

From source file:com.github.pennyfive.cinemafinlando.ui.fragment.generic.QueryAbsListFragment.java

private View inflateContentListView(Adapter adapter) {
    AbsListView view = createAbsListView();
    view.setId(R.id.list);//from   ww  w  . j a va2s. c o  m
    view.setOnItemClickListener(this);
    view.setAdapter(adapter);
    return view;
}

From source file:com.gigathinking.simpleapplock.AppListFragment.java

@Override
public void onStart() {
    super.onStart();

    if (!noAds) {
        final AdView adView = (AdView) getActivity().findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().addTestDevice("YOUR DEVICE 1")
                .addTestDevice("YOUR DEVICE 2").build();
        adView.loadAd(adRequest);//from   ww  w  . j  a v a 2s . co  m
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                LinearLayout ll = (LinearLayout) getActivity().findViewById(R.id.id_ll_app_list);
                ll.findViewById(R.id.adView).setVisibility(View.VISIBLE);
            }
        });
    } else {
        (getActivity().findViewById(R.id.adView)).setVisibility(View.GONE);
    }

    interstitial = new InterstitialAd(getActivity());
    interstitial.setAdUnitId("YOUR AD UNIT ID");
    interstitial.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            super.onAdClosed();
            mPrefs.edit().putInt("ad_count", (mPrefs.getInt("ad_count", 0) + 1)).commit();
        }
    });

    // Create ad request.
    AdRequest adRequestInterestial = new AdRequest.Builder().addTestDevice("YOUR DEVICE 1")
            .addTestDevice("YOUR DEVICE 2").build();

    // Begin loading your interstitial.
    if (!noAds) {
        interstitial.loadAd(adRequestInterestial);
    }

    if (!mList.isEmpty()) {
        showInitialStart(false);
    } else {
        showInitialStart(true);
    }
    AbsListView listView = (AbsListView) getActivity().findViewById(R.id.lv_app_list);
    listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(this);
    mAdapter = new AppListAdapter(getActivity(), R.layout.layout_applist_item, mList);
    listView.setAdapter(mAdapter);
    listView.setOnItemClickListener(this);
    receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (isAdded()) {
                startActivityForResult(new Intent(context, AppPicker.class), 22);
            }
        }
    };
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver,
            new IntentFilter(AppLockApplication.LAUNCH_PICKER));

    //Limit 5 interstitial ads per day.
    int today = Integer.parseInt(DateFormat.format("d", Calendar.getInstance()).toString());
    if (mPrefs.getInt("today", 0) != today) {
        mPrefs.edit().putInt("ad_count", 0).commit();
        mPrefs.edit().putInt("today", today).commit();
    }
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_folder, container, false);
    final AbsListView mListView = (AbsListView) view.findViewById(android.R.id.list);
    mListView.setAdapter(mAdapter);
    mListView.setOnItemClickListener(this);

    ((RadioButton) view.findViewById(android.R.id.button1))
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override/*from   ww w  . j  a  va2s .  c  o  m*/
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    if (isChecked) {
                        setFocus(ItemFocus.Visualization, getView());
                    }
                }
            });

    ((RadioButton) view.findViewById(android.R.id.button2))
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
                    if (isChecked) {
                        setFocus(ItemFocus.Json, getView());
                    }
                }
            });

    ((TextView) view.findViewById(R.id.json)).setMovementMethod(new ScrollingMovementMethod());

    refresh();

    return view;
}

From source file:org.deviceconnect.android.deviceplugin.theta.fragment.ThetaGalleryFragment.java

/**
 * ListView Initialize.//w ww.  j a  va  2  s .  c om
 *
 * @param rootView Root View
 */
private void initListView(final View rootView) {
    AbsListView list = (AbsListView) rootView.findViewById(R.id.theta_list);
    list.setAdapter(mGalleryAdapter);

    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> adapterView, final View view, final int position,
                final long id) {
            if ((mIsGalleryMode && !mUpdateAppList.get(position).isImage())
                    || (!mIsGalleryMode && !mUpdateThetaList.get(position).isImage())) {
                ThetaDialogFragment.showAlert(getActivity(), getString(R.string.theta_ssid_prefix),
                        getString(R.string.theta_error_unsupported_movie), null);
                return;
            }
            Intent intent = new Intent();
            intent.putExtra(ThetaFeatureActivity.FEATURE_MODE, ThetaFeatureActivity.MODE_VR);

            int index = -1;
            if (mUpdateThetaList.size() > 0) {
                index = mStorage.getThetaObjectCachesIndex(mUpdateThetaList.get(position).getFileName());
            }
            if (!mIsGalleryMode && index != -1) {
                intent.putExtra(ThetaFeatureActivity.FEATURE_IS_STORAGE, !mIsGalleryMode);
                intent.putExtra(ThetaFeatureActivity.FEATURE_DATA, index);
            } else {
                intent.putExtra(ThetaFeatureActivity.FEATURE_IS_STORAGE, mIsGalleryMode);
                intent.putExtra(ThetaFeatureActivity.FEATURE_DATA, position);
            }
            intent.setClass(getActivity(), ThetaFeatureActivity.class);
            startActivity(intent);
        }
    });
    list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(final AdapterView<?> adapterView, final View view, final int position,
                final long id) {
            if (!mIsGalleryMode && mUpdateThetaList.get(position).isImage()
                    && !existThetaData(mUpdateThetaList.get(position))) {
                ThetaDialogFragment.showSelectCommandDialog(getActivity(),
                        getResources().getStringArray(R.array.theta_gallery_command),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialogInterface, final int pos) {
                                FileManager fileManager = new FileManager(getActivity());
                                fileManager.checkWritePermission(new FileManager.CheckPermissionCallback() {
                                    @Override
                                    public void onSuccess() {
                                        if (pos == DIALOG_COMMAND_IMPORT) {
                                            Activity activity = getActivity();
                                            if (activity != null
                                                    && !ThetaObjectStorage.hasEnoughStorageSize()) {
                                                // Check Android Storage Limit
                                                activity.runOnUiThread(new Runnable() {
                                                    @Override
                                                    public void run() {
                                                        ThetaDialogFragment.showAlert(getActivity(),
                                                                getResources()
                                                                        .getString(R.string.theta_ssid_prefix),
                                                                getResources().getString(
                                                                        R.string.theta_error_import_shortage_by_android),
                                                                null);
                                                    }
                                                });
                                                return;
                                            }

                                            exeImportData(position);
                                        } else {
                                            showRemoveConfirmDialog(position);
                                        }
                                    }

                                    @Override
                                    public void onFail() {
                                        Activity activity = getActivity();
                                        if (activity != null) {
                                            activity.runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    ThetaDialogFragment.showAlert(getActivity(),
                                                            getResources()
                                                                    .getString(R.string.theta_ssid_prefix),
                                                            getResources().getString(
                                                                    R.string.theta_error_failed_save_file),
                                                            null);
                                                }
                                            });
                                        }

                                    }
                                });
                            }
                        });
            } else {
                FileManager fileManager = new FileManager(getActivity());
                fileManager.checkWritePermission(new FileManager.CheckPermissionCallback() {
                    @Override
                    public void onSuccess() {
                        showRemoveConfirmDialog(position);
                    }

                    @Override
                    public void onFail() {
                        Activity activity = getActivity();
                        if (activity != null) {
                            activity.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    ThetaDialogFragment.showAlert(getActivity(),
                                            getResources().getString(R.string.theta_ssid_prefix),
                                            getResources().getString(R.string.theta_error_failed_save_file),
                                            null);
                                }
                            });
                        }

                    }
                });

            }
            return true;
        }
    });
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void clearListViewChoices(final AbsListView view) {
    if (view == null)
        return;//  w  ww  .j  a v  a2  s  .com
    final ListAdapter adapter = view.getAdapter();
    if (adapter == null)
        return;
    view.clearChoices();
    view.setChoiceMode(AbsListView.CHOICE_MODE_NONE);
    // Workaround for Android bug
    // http://stackoverflow.com/questions/9754170/listview-selection-remains-persistent-after-exiting-choice-mode
    final int position = view.getFirstVisiblePosition(), offset = Utils.getFirstChildOffset(view);
    view.setAdapter(adapter);
    Utils.scrollListToPosition(view, position, offset);
}