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:sysnetlab.android.sdc.test.TestHelper.java

public static Activity cloneExperiment(ActivityInstrumentationTestCase2<?> testCase, Activity activity) {
    Assert.assertTrue("The acitivty must be a ViewExperimentActivity.",
            activity instanceof ViewExperimentActivity);

    Button buttonCloneExperiment = (Button) activity.findViewById(R.id.button_experiment_view_clone);
    Assert.assertNotNull("Button should not be null.", buttonCloneExperiment);

    ActivityMonitor monitor = testCase.getInstrumentation().addMonitor(CreateExperimentActivity.class.getName(),
            null, false);/*from  w  w  w.ja  va2 s  . c o m*/
    TouchUtils.clickView(testCase, buttonCloneExperiment);
    activity = testCase.getInstrumentation().waitForMonitorWithTimeout(monitor, 5000);
    Assert.assertTrue("activity should be CreateExperimentActivity.",
            activity instanceof CreateExperimentActivity);
    testCase.getInstrumentation().removeMonitor(monitor);

    return activity;
}

From source file:com.oliversride.wordryo.Utils.java

public static void setChecked(Activity activity, int id, boolean value) {
    CheckBox cbx = (CheckBox) activity.findViewById(id);
    cbx.setChecked(value);//from w  w  w. ja v a2  s  . c o m
}

From source file:com.waz.zclient.utils.ViewUtils.java

@SuppressLint("com.waz.ViewUtils")
public static <T extends View> T getView(@NonNull Activity activity, @IdRes int resId) {
    return (T) activity.findViewById(resId);
}

From source file:com.oliversride.wordryo.Utils.java

public static void setText(Activity activity, int id, String value) {
    EditText editText = (EditText) activity.findViewById(id);
    if (null != editText) {
        editText.setText(value, TextView.BufferType.EDITABLE);
    }//from   w  ww.j  a va2s .co m
}

From source file:edu.com.mvplibrary.ui.widget.StatusBarUtil.java

/**
 * ?/*www.j a  v a  2s .c  o  m*/
 */
private static void setRootView(Activity activity) {
    ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
    rootView.setFitsSystemWindows(true);
    rootView.setClipToPadding(true);
}

From source file:edu.com.mvplibrary.ui.widget.StatusBarUtil.java

/**
 * ???//from w  ww.  j  a v  a 2s.com
 *
 * @param activity       ? activity
 * @param statusBarAlpha ?
 */
private static void addTranslucentView(Activity activity, int statusBarAlpha) {
    ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
    // ??,??
    if (contentView.getChildCount() > 1) {
        contentView.removeViewAt(1);
    }
    contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha));
}

From source file:com.github.rutvijkumar.twittfuse.Util.java

public static void showNetworkUnavailable(Activity activity) {
    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.network_not_available,
            (ViewGroup) activity.findViewById(R.id.nwunavailable));
    Toast toast = new Toast(activity);
    toast.setView(view);// w  w w .jav a  2 s  .  c om
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.show();

}

From source file:com.sun.inject.Injector.java

private static final void injectViewByActivity(Field field, Activity act)
        throws IllegalArgumentException, IllegalAccessException {
    InjectView mInjectView = field.getAnnotation(InjectView.class);
    int idValue = mInjectView.value();
    //      Log.e(TAG, "\t\tidValue :" + idValue + " " + field);
    field.setAccessible(true);//from   www . ja  v a 2  s .c o  m
    Object injectObject = act.findViewById(idValue);
    //      Log.e(TAG, "\t\tinjectObject :" + injectObject);
    if (injectObject == null) {
        throw new IllegalStateException(
                "findViewById(" + idValue + ") gave null for " + field + ", can't inject");
    }
    field.set(act, injectObject);
    field.setAccessible(false);
}

From source file:org.proninyaroslav.libretorrent.core.utils.Utils.java

public static void showActionModeStatusBar(Activity activity, boolean mode) {
    int color = (mode ? R.color.action_mode_dark : R.color.primary_dark);
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        RelativeLayout statusBar = (RelativeLayout) activity.findViewById(R.id.statusBarKitKat);
        statusBar.setBackground(ContextCompat.getDrawable(activity, color));
        statusBar.setVisibility(View.VISIBLE);

    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, color));
    }/* w w w.j  av  a  2  s .  com*/
}

From source file:com.bangalore.barcamp.BCBUtils.java

public static void createActionBarOnActivity(final Activity activity, boolean isHome) {
    // ******** Start of Action Bar configuration
    ActionBar actionbar = (ActionBar) activity.findViewById(R.id.actionBar1);
    actionbar.setHomeLogo(R.drawable.home);
    actionbar.setHomeAction(new Action() {
        @Override//from w  w  w . j  a  v a 2  s . c om
        public void performAction(View view) {
            ((SlidingMenuActivity) activity).toggle();
        }

        @Override
        public int getDrawable() {
            return R.drawable.home;
        }
    });

    actionbar.setTitle(R.string.app_title_text);
    TextView logo = (TextView) activity.findViewById(R.id.actionbar_title);
    Shader textShader = new LinearGradient(0, 0, 0, logo.getHeight(), new int[] { Color.WHITE, 0xff999999 },
            null, TileMode.CLAMP);
    logo.getPaint().setShader(textShader);
    actionbar.setOnTitleClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

        }
    });
    // ******** End of Action Bar configuration

}