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.dmitrymalkovich.android.popularmoviesapp.details.MovieDetailFragment.java

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

    Activity activity = getActivity();
    CollapsingToolbarLayout appBarLayout = (CollapsingToolbarLayout) activity.findViewById(R.id.toolbar_layout);
    if (appBarLayout != null && activity instanceof MovieDetailActivity) {
        appBarLayout.setTitle(mMovie.getTitle());
    }//  w w w  .  ja v  a 2 s . c o  m

    ImageView movieBackdrop = ((ImageView) activity.findViewById(R.id.movie_backdrop));
    if (movieBackdrop != null) {
        Picasso.with(activity).load(mMovie.getBackdropUrl(getContext())).config(Bitmap.Config.RGB_565)
                .into(movieBackdrop);
    }
}

From source file:org.schabi.terminightor.AlarmItemDetailFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    lastSavedInstaneState = savedInstanceState;
    Activity a = getActivity();
    setAlarmTimeView = (TextView) a.findViewById(R.id.setAlarmTimeView);
    setAlarmAMPMView = (TextView) a.findViewById(R.id.setAlarmAmPmSuffix);
    repeatCheckBox = (CheckBox) a.findViewById(R.id.setRepeatCheckBox);
    chooseDateView = (ChooseDaysView) a.findViewById(R.id.chooseDateView);
    alarmLabelBox = (EditText) a.findViewById(R.id.setAlarmLabelBox);
    setAlarmToneButton = (Button) a.findViewById(R.id.setAlarmToneButton);
    vibrateCheckBox = (CheckBox) a.findViewById(R.id.vibrateCheckBox);
    nfcTagLabelView = (ImageView) a.findViewById(R.id.nfcTagLabelView);
    nfcTagIdView = (TextView) a.findViewById(R.id.nfcTagIdView);
    addNfcTabButton = (FloatingActionButton) a.findViewById(R.id.addNfcTagButton);

    repeatCheckBox.setOnClickListener(new View.OnClickListener() {
        @Override/*  w w w  .ja  va  2s.co  m*/
        public void onClick(View v) {
            if (repeatCheckBox.isChecked()) {
                chooseDateView.setVisibility(View.VISIBLE);
            } else {
                chooseDateView.setVisibility(View.GONE);
            }
            chooseDateView.setRepeatEnabled(repeatCheckBox.isChecked());
        }
    });

    setAlarmTimeView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            timePickerDialog.show();
        }
    });

    setAlarmToneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
                    getResources().getString(R.string.selectAlarmToneTitle));
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM);
            if (!alarm.getAlarmTone().isEmpty()) {
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(alarm.getAlarmTone()));
            }
            startActivityForResult(intent, SET_ALARM_TONE);
        }
    });

    addNfcTabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), SetTagActivity.class);
            startActivityForResult(intent, READ_NFC_ID);
        }
    });
}

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

public void updateThumbnail(Bitmap thumbnail, int id) {
    Activity a = getActivity();
    ImageView thumbnailView = null;
    try {/*from   w  ww  .  j  a v a 2  s . com*/
        switch (id) {
        case SetThumbnailRunnable.VIDEO_THUMBNAIL:

            thumbnailView = (ImageView) a.findViewById(R.id.detailThumbnailView);
            break;
        case SetThumbnailRunnable.CHANNEL_THUMBNAIL:
            thumbnailView = (ImageView) a.findViewById(R.id.detailUploaderThumbnailView);
            break;
        default:
            Log.d(TAG, "Error: Thumbnail id not known");
            return;
        }
        if (thumbnailView != null) {
            thumbnailView.setImageBitmap(thumbnail);
        }
    } catch (java.lang.NullPointerException e) {
        // No god programm design i know. :/
        Log.w(TAG, "updateThumbnail(): Fragment closed before thread ended work");
    }
}

From source file:de.schramke.android.navdrawer.NavigationDrawer.java

public NavigationDrawer(Activity activity) throws IllegalArgumentException {
    this.activity = activity;
    this.drawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);
    this.drawerList = (ListView) activity.findViewById(R.id.drawer_list);

    listeners = new HashSet<NavigationDrawerListener>();
    itemListeners = new HashSet<NavigationDrawerItemListener>();
    internListeners = new HashSet<DrawerLayout.DrawerListener>();

    if (activity instanceof NavigationDrawerListener) {
        listeners.add((NavigationDrawerListener) activity);
    }/* w  ww .j  a  v  a 2  s .  co  m*/

    if (activity instanceof NavigationDrawerItemListener) {
        itemListeners.add((NavigationDrawerItemListener) activity);
    }

    if (this.drawerLayout == null) {
        final String errerMsg = activity.getString(R.string.exception_drawer_layout);
        throw new IllegalArgumentException(errerMsg);
    }

    if (this.drawerList == null) {
        final String errerMsg = activity.getString(R.string.exception_drawer_list);
        throw new IllegalArgumentException(errerMsg);
    }

    this.drawerLayout.setDrawerListener(this);
    this.drawerList.setOnItemClickListener(this);
    this.drawerList.setOnItemLongClickListener(this);
    this.drawerList.setOnItemSelectedListener(this);
    this.drawerLayout.closeDrawers();

    this.drawerMenu = new android.support.v7.internal.view.menu.MenuBuilder(activity);
    if (activity instanceof NavigationDrawerCreateListener) {
        ((NavigationDrawerCreateListener) activity).onCreateNavigationDrawerMenu(drawerMenu);
    }

    this.drawerList.setAdapter(new NavDrawerAdapter());
}

From source file:com.google.android.gcm.demo.ui.InstanceIdFragment.java

@Override
public void refresh() {
    new AsyncTask<Void, Void, Void>() {
        @Override// w w  w.  j av a 2  s. c  o  m
        protected Void doInBackground(Void... params) {
            final String instanceId = mInstanceIdHelper.getInstanceId();
            final String creationTime = DateFormat.getDateTimeInstance()
                    .format(new Date(mInstanceIdHelper.getCreationTime()));
            final Activity activity = getActivity();
            if (activity != null) {
                Handler handler = new Handler(activity.getMainLooper());
                handler.post(new Runnable() {
                    public void run() {
                        setValue(activity.findViewById(R.id.iid_instance_id), instanceId);
                        setValue(activity.findViewById(R.id.iid_creation_time), creationTime);
                    }
                });
            }
            return null;
        }
    }.execute();
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        if (sender.appTokens.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Token token : sender.appTokens.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.smartphone_grey600);
                label.setText(token.scope + " - " + AbstractFragment.truncateToMediumString(token.token));
                button.setText(R.string.iid_delete_token);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_scope, token.scope);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.iid_no_tokens));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout tokensView = (FrameLayout) getActivity().findViewById(R.id.iid_tokens_wrapper);
    tokensView.removeAllViews();
    tokensView.addView(sendersList);
}

From source file:ru.valle.btc.MainActivityTest.java

public void testLayoutOnStart() {
    Activity activity = getActivity();
    assertTrue(activity.findViewById(R.id.send_layout).getVisibility() == View.GONE);
    assertTrue(activity.findViewById(R.id.spend_tx_description).getVisibility() == View.GONE);
    assertTrue(activity.findViewById(R.id.spend_tx).getVisibility() == View.GONE);
    activity.finish();/*from  w ww  .  j a va  2  s  . c o  m*/
}

From source file:com.ultramegasoft.flavordex2.fragment.ViewInfoFragment.java

/**
 * Populates the table of extra fields./*from   w w w .j av a2 s .  c o  m*/
 *
 * @param data A LinkedHashMap containing the extra values
 */
protected void populateExtras(@NonNull LinkedHashMap<String, ExtraFieldHolder> data) {
    final Activity activity = getActivity();
    if (activity == null) {
        return;
    }

    final TableLayout table = activity.findViewById(R.id.entry_info);
    if (!mExtraRows.isEmpty()) {
        for (View tableRow : mExtraRows) {
            table.removeView(tableRow);
        }
        mExtraRows.clear();
    }
    if (data.size() > 0) {
        final LayoutInflater inflater = LayoutInflater.from(activity);
        for (ExtraFieldHolder extra : data.values()) {
            if (extra.preset) {
                continue;
            }
            final View root = inflater.inflate(R.layout.view_info_extra, table, false);
            ((TextView) root.findViewById(R.id.label)).setText(getString(R.string.label_field, extra.name));
            ((TextView) root.findViewById(R.id.value)).setText(extra.value);
            table.addView(root);
            mExtraRows.add(root);
        }
    }
}

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

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

    mContext = getActivity();// www.j a  v  a2 s  .  co m
    mCurrentUser = new ListUser(mContext);
    mMessageHelper = new MessageHelper(mContext);
    mRequestMethods = new RequestMethods(mContext);

    Activity activity = getActivity();

    //UI Elements
    mEmptyView = (TextView) getActivity().findViewById(R.id.empty_gallery_label);
    mProgressBar = (ProgressBar) getActivity().findViewById(R.id.gallery_progressBar);

    //RecyclerView
    mSwipeRefreshLayout = (SwipeRefreshLayout) activity.findViewById(R.id.gallerySwipeRefresh);
    mRecyclerView = (RecyclerView) activity.findViewById(R.id.galleryRecyclerView);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.hasFixedSize();
    mGridLayoutManager = new GridLayoutManager(activity, 3);
    mGalleryAdapter = new GalleryAdapter(mContext, mPhotoList);
    mRecyclerView.setAdapter(mGalleryAdapter);
    mRecyclerView.setLayoutManager(mGridLayoutManager);
    mRecyclerView.addOnItemTouchListener(
            new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    ArrayList<String> urls = new ArrayList<>();

                    for (int i = 0; i < mPhotoList.size(); i++) {
                        GalleryItem singlePhoto = mPhotoList.get(i);
                        urls.add(singlePhoto.getUrl() + "/800"); //TODO: test this! when 1024 images are generated
                    }
                    mCallback.viewImage(urls, position); //TODO: eventually set url for large image
                }
            }));

    //Show user Photos
    refreshItems();

    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refreshItems();
            mSwipeRefreshLayout.setRefreshing(false);
        }
    });
}

From source file:com.esminis.server.library.activity.main.MainViewImpl.java

@Override
public void setMessage(boolean preloaderBackground, boolean preloader, String buttonTitle, String message) {
    final Activity activity = this.activity.get();
    if (activity == null) {
        return;/*from   w w w  .  j  a  v  a 2s .  c  o m*/
    }
    activity.findViewById(R.id.preloader_container)
            .setVisibility(preloaderBackground ? View.VISIBLE : View.GONE);
    if (preloaderBackground) {
        final Button button = (Button) activity.findViewById(R.id.preloader_button_ok);
        button.setVisibility(buttonTitle != null ? View.VISIBLE : View.GONE);
        button.setText(buttonTitle);
        activity.findViewById(R.id.preloader).setVisibility(preloader ? View.VISIBLE : View.GONE);
        TextView textView = (TextView) activity.findViewById(R.id.preloader_label);
        textView.setMovementMethod(new ScrollingMovementMethod());
        textView.setText(message);
    }
}

From source file:com.digiplex.extra.grantpermissiondemo.ContactDetailsFragment.java

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

    long personId = getArguments().getLong(ContactActivity.SELECTED_CONTACT_ID);// getIntent().getLongExtra("id", 0);
    Activity activity = getActivity();

    Uri phonesUri = Phone.CONTENT_URI;
    String[] projection = new String[] { Phone._ID, Phone.DISPLAY_NAME, Phone.TYPE, Phone.NUMBER, Phone.LABEL };
    String selection = Phone.CONTACT_ID + " = ?";
    String[] selectionArgs = new String[] { Long.toString(personId) };

    mCursor = activity.getContentResolver().query(phonesUri, projection, selection, selectionArgs, null);

    mDisplayName = (TextView) activity.findViewById(R.id.display_name);
    if (mCursor.moveToFirst()) {
        mDisplayName.setText(mCursor.getString(mCursor.getColumnIndex(Phone.DISPLAY_NAME)));
    }/*from   w  ww.ja va2  s  . co  m*/

    ListAdapter adapter = new PhoneNumbersAdapter(this.getActivity(), R.layout.list_item_phone_number, mCursor,
            new String[] { Phone.TYPE, Phone.NUMBER }, new int[] { R.id.label, R.id.phone_number });
    setListAdapter(adapter);
}