Example usage for android.app Activity findViewById

List of usage examples for android.app Activity findViewById

Introduction

In this page you can find the example usage for android.app Activity findViewById.

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds a view that was identified by the android:id XML attribute that was processed in #onCreate .

Usage

From source file:com.ultramegatech.ey.ElementListFragment.java

/**
 * Setup the listener for the filtering TextView.
 *///from  w w w . ja  va2 s.c o  m
private void setupFilter() {
    final Activity activity = getActivity();
    if (activity == null) {
        return;
    }

    final EditText filterEditText = (EditText) activity.findViewById(R.id.filter);
    filterEditText.addTextChangedListener(new TextWatcher() {
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        public void afterTextChanged(Editable s) {
            mFilter = s.toString();
            mAdapter.getFilter().filter(mFilter);
        }
    });
}

From source file:org.uab.deic.uabdroid.solutions.unit3.FormFragment.java

@Override
public void onActivityCreated(Bundle _savedInstanceState) {
    super.onActivityCreated(_savedInstanceState);

    // As we are in a fragment, we need the parent activity instance in order to have access 
    // to the activity's SharedPreferences and the layout Views
    final Activity parentActivity = getActivity();

    SharedPreferences activityPreferences = parentActivity.getPreferences(Context.MODE_PRIVATE);

    mEditTextName = (EditText) parentActivity.findViewById(R.id.edittext_form_name);
    mEditTextDeveloper = (EditText) parentActivity.findViewById(R.id.edittext_form_developer);
    mDatePickerDate = (DatePicker) parentActivity.findViewById(R.id.datepicker_form_date);
    mEditTextURL = (EditText) parentActivity.findViewById(R.id.edittext_form_url);

    // if the last run of the activity wasn't finished using the Accept or Cancel buttons
    // then we must restore the state
    if (activityPreferences.getBoolean(FormAppActivity.STATE_NOT_SAVED, false)) {
        // Restore the name
        mEditTextName.setText(activityPreferences.getString(FormAppActivity.FORM_FIELD_NAME, ""));

        // Restore the developer name
        mEditTextDeveloper.setText(activityPreferences.getString(FormAppActivity.FORM_FIELD_DEVELOPER, ""));

        // Restore the calendar. The default values are extracted from Calendar, which is 
        // instantiated with the current date
        Calendar calendar = Calendar.getInstance();
        int day = activityPreferences.getInt(FormAppActivity.FORM_FIELD_DAY,
                calendar.get(Calendar.DAY_OF_MONTH));
        int month = activityPreferences.getInt(FormAppActivity.FORM_FIELD_MONTH,
                calendar.get(Calendar.MONTH) + 1);
        int year = activityPreferences.getInt(FormAppActivity.FORM_FIELD_YEAR, calendar.get(Calendar.YEAR));

        mDatePickerDate.updateDate(year, month, day);

        // Restore the URL
        mEditTextURL.setText(activityPreferences.getString(FormAppActivity.FORM_FIELD_URL, ""));

        // Finally, we restore the state of STATE_NOT_SAVED to false
        SharedPreferences.Editor editor = activityPreferences.edit();
        editor.putBoolean(FormAppActivity.STATE_NOT_SAVED, false);
        editor.commit();/*from  ww  w.  ja  v a2  s. c  o m*/
    }

    Button cleanButton = (Button) parentActivity.findViewById(R.id.button_form_clean);
    cleanButton.setOnClickListener(new OnClickListener() {
        // When the button is clicked, we erase the content of the controls
        // o reset them to the default value
        @Override
        public void onClick(View v) {
            mEditTextName.setText("");
            mEditTextDeveloper.setText("");
            Calendar calendar = Calendar.getInstance();
            mDatePickerDate.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1,
                    calendar.get(Calendar.DAY_OF_MONTH));
            mEditTextURL.setText("");
        }
    });

    Button acceptButton = (Button) parentActivity.findViewById(R.id.button_form_accept);
    acceptButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.DAY_OF_MONTH, mDatePickerDate.getDayOfMonth());
            calendar.set(Calendar.MONTH, mDatePickerDate.getMonth() - 1);
            calendar.set(Calendar.YEAR, mDatePickerDate.getYear());

            String name = mEditTextName.getText().toString();
            String developer = mEditTextDeveloper.getText().toString();
            String url = mEditTextURL.getText().toString();

            Intent intent = new Intent(parentActivity, ResultsActivity.class);

            // Store the data in the intent bundle
            intent.putExtra("name", name);
            intent.putExtra("developer", name);
            intent.putExtra("date", mDatePickerDate.getDayOfMonth() + "/" + mDatePickerDate.getMonth() + "/"
                    + mDatePickerDate.getYear());
            intent.putExtra("url", name);

            // Store the data for the App Singleton
            MyApplication.getInstance().setData(AppData.getInstance(name, developer, calendar, url));

            // Store the data in the database
            DatabaseAdapter databaseAdapter = new DatabaseAdapter(parentActivity);
            databaseAdapter.open();
            databaseAdapter.insertApp(name, developer, calendar, url);
            databaseAdapter.close();

            // Indicating that the activity is finished by the use of the button
            ((FormAppActivity) parentActivity).setButtonPressed();

            startActivity(intent);
            // As we have finished with this activity, we finalized it so 
            // the user never returns to it when the back button is pressed
            parentActivity.finish();
        }
    });

    Button cancelButton = (Button) parentActivity.findViewById(R.id.button_form_cancel);
    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Finishing the activity by the use of the button
            ((FormAppActivity) parentActivity).setButtonPressed();
            parentActivity.finish();
        }
    });
}

From source file:in.rab.ordboken.Ordboken.java

public SearchView initSearchView(Activity activity, Menu menu, String query, Boolean focus) {
    SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) activity.findViewById(R.id.mySearchView);

    searchView.setSearchableInfo(/* w  w w . j  ava2s .  com*/
            searchManager.getSearchableInfo(new ComponentName(activity, MainActivity.class)));

    // Hack to get the magnifying glass icon inside the EditText
    searchView.setIconifiedByDefault(true);
    searchView.setIconified(false);

    // Hack to get rid of the collapse button
    searchView.onActionViewExpanded();

    if (!focus) {
        searchView.clearFocus();
    }

    // searchView.setSubmitButtonEnabled(true);
    searchView.setQueryRefinementEnabled(true);

    if (query != null) {
        searchView.setQuery(query, false);
    }

    return searchView;
}

From source file:de.tudarmstadt.informatik.secuso.phishedu2.PhishBaseActivity.java

protected void updateScore() {
    Activity view = getActivity();
    if (view != null) {
        updateScore(view.findViewById(R.id.score_relative));
    }/* w  ww.j a  v a 2 s.  c o m*/
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.view.TextModalInteractionView.java

@Override
public void doOnCreate(final Activity activity, Bundle onSavedInstanceState) {
    activity.setContentView(R.layout.apptentive_textmodal_interaction_center);

    TextView title = (TextView) activity.findViewById(R.id.title);
    if (interaction.getTitle() == null) {
        title.setVisibility(View.GONE);
    } else {/*from  ww  w.ja  v a  2  s  . c o  m*/
        title.setText(interaction.getTitle());
    }
    TextView body = (TextView) activity.findViewById(R.id.body);
    if (interaction.getBody() == null) {
        body.setVisibility(View.GONE);
    } else {
        body.setText(interaction.getBody());
    }

    LinearLayout bottomArea = (LinearLayout) activity.findViewById(R.id.bottom_area);
    List<Action> actions = interaction.getActions().getAsList();
    boolean vertical;
    if (actions != null && !actions.isEmpty()) {
        int totalChars = 0;
        for (Action button : actions) {
            totalChars += button.getLabel().length();
        }
        if (actions.size() == 1) {
            vertical = false;
        } else if (actions.size() == 2) {
            vertical = totalChars > MAX_TEXT_LENGTH_FOR_TWO_BUTTONS;
        } else if (actions.size() == 3) {
            vertical = totalChars > MAX_TEXT_LENGTH_FOR_THREE_BUTTONS;
        } else if (actions.size() == 4) {
            vertical = totalChars > MAX_TEXT_LENGTH_FOR_FOUR_BUTTONS;
        } else {
            vertical = true;
        }
        if (vertical) {
            bottomArea.setOrientation(LinearLayout.VERTICAL);
        } else {
            bottomArea.setOrientation(LinearLayout.HORIZONTAL);
        }

        for (int i = 0; i < actions.size(); i++) {
            final Action buttonAction = actions.get(i);
            final int position = i;
            ApptentiveDialogButton button = new ApptentiveDialogButton(activity);
            button.setText(buttonAction.getLabel());
            switch (buttonAction.getType()) {
            case dismiss:
                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        JSONObject data = new JSONObject();
                        try {
                            data.put(TextModalInteraction.EVENT_KEY_ACTION_ID, buttonAction.getId());
                            data.put(Action.KEY_LABEL, buttonAction.getLabel());
                            data.put(TextModalInteraction.EVENT_KEY_ACTION_POSITION, position);
                        } catch (JSONException e) {
                            Log.e("Error creating Event data object.", e);
                        }
                        EngagementModule.engageInternal(activity, interaction,
                                TextModalInteraction.EVENT_NAME_DISMISS, data.toString());
                        activity.finish();
                    }
                });
                break;
            case interaction:
                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        LaunchInteractionAction launchInteractionButton = (LaunchInteractionAction) buttonAction;
                        List<Invocation> invocations = launchInteractionButton.getInvocations();
                        String interactionIdToLaunch = null;
                        for (Invocation invocation : invocations) {
                            if (invocation.isCriteriaMet(activity)) {
                                interactionIdToLaunch = invocation.getInteractionId();
                                break;
                            }
                        }

                        Interaction invokedInteraction = null;
                        if (interactionIdToLaunch != null) {
                            Interactions interactions = InteractionManager.getInteractions(activity);
                            if (interactions != null) {
                                invokedInteraction = interactions.getInteraction(interactionIdToLaunch);
                            }
                        }

                        JSONObject data = new JSONObject();
                        try {
                            data.put(TextModalInteraction.EVENT_KEY_ACTION_ID, buttonAction.getId());
                            data.put(Action.KEY_LABEL, buttonAction.getLabel());
                            data.put(TextModalInteraction.EVENT_KEY_ACTION_POSITION, position);
                            data.put(TextModalInteraction.EVENT_KEY_INVOKED_INTERACTION_ID,
                                    invokedInteraction == null ? JSONObject.NULL : invokedInteraction.getId());
                        } catch (JSONException e) {
                            Log.e("Error creating Event data object.", e);
                        }

                        EngagementModule.engageInternal(activity, interaction,
                                TextModalInteraction.EVENT_NAME_INTERACTION, data.toString());
                        if (invokedInteraction != null) {
                            EngagementModule.launchInteraction(activity, invokedInteraction);
                        }

                        activity.finish();
                    }
                });
                break;
            }
            bottomArea.addView(button);
        }
    } else {
        bottomArea.setVisibility(View.GONE);
    }
}

From source file:com.github.ksoichiro.android.observablescrollview.test.ViewPagerTab2RecyclerViewFragment.java

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

    Activity parentActivity = getActivity();
    final ObservableRecyclerView recyclerView = (ObservableRecyclerView) view.findViewById(R.id.scroll);
    recyclerView.setLayoutManager(new LinearLayoutManager(parentActivity));
    recyclerView.setHasFixedSize(false);
    UiTestUtils.setDummyData(getActivity(), recyclerView);
    recyclerView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.container));

    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        recyclerView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }/*from  w ww  .j  ava2  s  . c o  m*/
    return view;
}

From source file:com.pemikir.youtubeplus.VideoItemDetailFragment.java

public void updateInfo(VideoInfo info) {
    Activity a = getActivity();
    try {/*from w  w w  .j  a va 2s . c o  m*/
        ProgressBar progressBar = (ProgressBar) a.findViewById(R.id.detailProgressBar);
        TextView videoTitleView = (TextView) a.findViewById(R.id.detailVideoTitleView);
        TextView uploaderView = (TextView) a.findViewById(R.id.detailUploaderView);
        TextView viewCountView = (TextView) a.findViewById(R.id.detailViewCountView);
        TextView thumbsUpView = (TextView) a.findViewById(R.id.detailThumbsUpCountView);
        TextView thumbsDownView = (TextView) a.findViewById(R.id.detailThumbsDownCountView);
        TextView uploadDateView = (TextView) a.findViewById(R.id.detailUploadDateView);
        TextView descriptionView = (TextView) a.findViewById(R.id.detailDescriptionView);
        ImageView thumbnailView = (ImageView) a.findViewById(R.id.detailThumbnailView);
        ImageView uploaderThumbnailView = (ImageView) a.findViewById(R.id.detailUploaderThumbnailView);
        ImageView thumbsUpPic = (ImageView) a.findViewById(R.id.detailThumbsUpImgView);
        ImageView thumbsDownPic = (ImageView) a.findViewById(R.id.detailThumbsDownImgView);
        View textSeperationLine = a.findViewById(R.id.textSeperationLine);

        if (textSeperationLine != null) {
            textSeperationLine.setVisibility(View.VISIBLE);
        }
        progressBar.setVisibility(View.GONE);
        videoTitleView.setVisibility(View.VISIBLE);
        uploaderView.setVisibility(View.VISIBLE);
        uploadDateView.setVisibility(View.VISIBLE);
        viewCountView.setVisibility(View.VISIBLE);
        thumbsUpView.setVisibility(View.VISIBLE);
        thumbsDownView.setVisibility(View.VISIBLE);
        uploadDateView.setVisibility(View.VISIBLE);
        descriptionView.setVisibility(View.VISIBLE);
        thumbnailView.setVisibility(View.VISIBLE);
        uploaderThumbnailView.setVisibility(View.VISIBLE);
        thumbsUpPic.setVisibility(View.VISIBLE);
        thumbsDownPic.setVisibility(View.VISIBLE);

        switch (info.videoAvailableStatus) {
        case VideoInfo.VIDEO_AVAILABLE: {
            videoTitleView.setText(info.title);
            uploaderView.setText(info.uploader);
            viewCountView.setText(info.view_count + " " + a.getString(R.string.viewSufix));
            thumbsUpView.setText(info.like_count);
            thumbsDownView.setText(info.dislike_count);
            uploadDateView.setText(a.getString(R.string.uploadDatePrefix) + " " + info.upload_date);
            descriptionView.setText(Html.fromHtml(info.description));
            descriptionView.setMovementMethod(LinkMovementMethod.getInstance());

            ActionBarHandler.getHandler().setVideoInfo(info.webpage_url, info.title);

            // parse streams
            Vector<VideoInfo.VideoStream> streamsToUse = new Vector<>();
            for (VideoInfo.VideoStream i : info.videoStreams) {
                if (useStream(i, streamsToUse)) {
                    streamsToUse.add(i);
                }
            }
            VideoInfo.VideoStream[] streamList = new VideoInfo.VideoStream[streamsToUse.size()];
            for (int i = 0; i < streamList.length; i++) {
                streamList[i] = streamsToUse.get(i);
            }
            ActionBarHandler.getHandler().setStreams(streamList, info.audioStreams);
        }
            break;
        case VideoInfo.VIDEO_UNAVAILABLE_GEMA:
            thumbnailView.setImageBitmap(
                    BitmapFactory.decodeResource(getResources(), R.drawable.gruese_die_gema_unangebracht));
            break;
        case VideoInfo.VIDEO_UNAVAILABLE:
            thumbnailView.setImageBitmap(
                    BitmapFactory.decodeResource(getResources(), R.drawable.not_available_monkey));
            break;
        default:
            Log.e(TAG, "Video Availeble Status not known.");
        }

        if (autoPlayEnabled) {
            ActionBarHandler.getHandler().playVideo();
        }
    } catch (java.lang.NullPointerException e) {
        Log.w(TAG, "updateInfo(): Fragment closed before thread ended work... or else");
        e.printStackTrace();
    }
}

From source file:com.jefftharris.passwdsafe.lib.DynamicPermissionMgr.java

/**
 * Constructor/*w w w .  j a  va2 s  . c om*/
 */
public DynamicPermissionMgr(String perm, Activity act, int permsRequestCode, int appSettingsRequestCode,
        String packageName, int reloadId, int appSettingsId) {
    itsPerm = perm;
    itsActivity = act;
    itsPermsRequestCode = permsRequestCode;
    itsAppSettingsRequestCode = appSettingsRequestCode;
    itsPackageName = packageName;

    itsReloadBtn = act.findViewById(reloadId);
    itsReloadBtn.setOnClickListener(this);
    itsAppSettingsBtn = act.findViewById(appSettingsId);
    itsAppSettingsBtn.setOnClickListener(this);
}

From source file:org.creativecommons.thelist.fragments.NavigationDrawerFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mContext = getActivity();/*w  w w .j  ava2  s . co  m*/
    Activity activity = getActivity();

    //Helpers
    mCurrentUser = new ListUser(mContext);
    mSharedPref = new SharedPreferencesMethods(mContext);

    //UI Elements
    mAccountName = (TextView) activity.findViewById(R.id.drawer_account_name);
    mAccountButton = (RelativeLayout) activity.findViewById(R.id.drawer_account_button);
    mAccountButtonLabel = (TextView) activity.findViewById(R.id.drawer_account_label);
    mAccountButtonIcon = (ImageView) activity.findViewById(R.id.drawer_account_icon);

    mAccountButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCallback.onAccountClicked();
        }
    });

    //RecyclerView
    mAdapter = new DrawerAdapter(mContext, getData());
    mDrawerRecyclerView = (RecyclerView) activity.findViewById(R.id.drawer_recyclerView);
    mDrawerRecyclerView.setAdapter(mAdapter);
    mDrawerRecyclerView.setHasFixedSize(true);
    mDrawerRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    mDrawerRecyclerView.addOnItemTouchListener(
            new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    //TODO: on item click load fragment
                    mCallback.onDrawerClicked(position);
                }
            }));

    mUserLearnedDrawer = mSharedPref.getUserLearnedDrawer();

}

From source file:de.k3b.android.locationMapViewer.geobmp.BookmarkListOverlay.java

public BookmarkListOverlay(Activity context, AdditionalPoints additionalPointProvider) {
    this.additionalPointProvider = additionalPointProvider;
    bookMarkController = new BookmarkListController(context,
            (ListView) context.findViewById(android.R.id.list));
    bookMarkController.setSelChangedListener(new BookmarkListController.OnSelChangedListener() {
        @Override//  ww  w  . j  a  v  a  2  s .  c  o m
        public void onSelChanged(GeoBmpDto newSelection) {
            BookmarkListOverlay.this.onSelChanged(newSelection);
        }
    });

    this.context = context;
    createButtons();
}