Activity findViewById - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Activity findViewById method.

This code example shows how to use the following methods:findViewById
   
    protected void setUp() throws Exception { 
      super.setUp(); 
      mInstr = this.getInstrumentation();
      testActivity = this.getActivity();
      containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
      innerContainer = (LinearLayout) containerView.getChildAt(0);
      testView = (CordovaWebView) innerContainer.getChildAt(0);
      touch = new TouchUtils();
      touchTool = new Purity(testActivity, getInstrumentation());
    } 
   
   
    public void testIframeDest() 
    { 
        testView.sendJavascript("loadUrl('http://maps.google.com/maps?output=embed');");
        sleep(3000); 
        testView.sendJavascript("loadUrl('index2.html')");
        sleep(1000); 
        String url = testView.getUrl();
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:findViewById, getWindow, getTheme
 
		if (getParent() != null)
			throw new IllegalStateException("This SlidingMenu appears to already be attached");
 
		// get the window background 
		TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] {android.R.attr.windowBackground});
		int background = a.getResourceId(0, 0);
		a.recycle();
 
		switch (slideStyle) {
		case SLIDING_WINDOW:
			mActionbarOverlay = false;
			ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
			ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
			// save ActionBar themes that have transparent assets 
			decorChild.setBackgroundResource(background);
			decor.removeView(decorChild);
			decor.addView(this);
			setContent(decorChild);
			break; 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:findViewById
		this.view = contentView.getRootView();
	} 
 
	/** Create snapshot handler that captures the view with target id of the activity. */ 
	public ScreenShot(Activity activity, int id) {
		this.view = activity.findViewById(id);
	} 
	 
	/** Take a snapshot of the view. */ 
	public Bitmap snap() {
		Bitmap bitmap = Bitmap.createBitmap(this.view.getWidth(),
				this.view.getHeight(), Config.ARGB_8888);
		Canvas canvas = new Canvas(bitmap);
		view.draw(canvas);
		return bitmap;
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:findViewById, getResources
	 * @param drawable 
	 *            Ресурс фона, подлежащего повторению. 
	 */ 
	public static void setTiledBackground(Activity activity, int view,
			int drawable) {
		Bitmap bitmap = BitmapFactory.decodeResource(activity.getResources(),
				drawable);
		BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
		bitmapDrawable.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
		activity.findViewById(view).setBackgroundDrawable(bitmapDrawable);
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:findViewById
	public static void gotoUrl(Context context, int resId) throws ActivityNotFoundException {
		gotoUrl(context, context.getString(resId));
	} 
 
	public static String getEditText(Activity act, int resId) {
		TextView te =  (TextView) act.findViewById(resId);
		assert(te == null);
		 
		if (te != null) {
			return te.getText().toString();
		} else { 
			return ""; 
		} 
	} 
	 
	public static void setEditText(Activity act, int resId, String str) {
		TextView te =  (TextView) act.findViewById(resId);
		assert(te == null);
		 
		if (te != null) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:findViewById
		return v;
	} 
 
	public static <T extends View> T findViewById(Activity activity, int id) {
		@SuppressWarnings("unchecked") 
		T v = (T) activity.findViewById(id);
		return v;
	} 
 
	public static void setInvisible(boolean invisible, View... views) {
		for (View view : views) {
			view.setVisibility(invisible ? INVISIBLE : VISIBLE);
		} 
	} 
 
	public static void setGone(boolean gone, View... views) {
		for (View view : views) {
			view.setVisibility(gone ? GONE : VISIBLE);
		} 
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:findViewById
                return; 
            } catch (NoSuchMethodException e) {
                // Oh well. We'll use the other mechanism below instead. 
            } 
 
            final View home = activity.findViewById(android.R.id.home);
            if (home == null) {
                // Action bar doesn't have a known configuration, an OEM messed with things. 
                return; 
            } 
 
            final ViewGroup parent = (ViewGroup) home.getParent();
            final int childCount = parent.getChildCount();
            if (childCount != 2) {
                // No idea which one will be the right one, an OEM messed with things. 
                return; 
            } 
 
            final View first = parent.getChildAt(0);
            final View second = parent.getChildAt(1);
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:findViewById
     */ 
    public void clickButton(final Activity activity, final int buttonResourceId) throws Throwable {
        runOnUiThreadAndGetTheResult(new Callable<Void>() {
            @Override 
            public Void call() throws Exception {
                View view = activity.findViewById(buttonResourceId);
                Assert.assertNotNull(view);
                if (view.isEnabled()) {
                    view.performClick();
                } 
                return null; 
            } 
        }); 
    } 
 
    /** Returns the result of running {@link TextView#getText()} on the ui thread. */ 
    public CharSequence getText(final TextView view) throws Throwable {
        return runOnUiThreadAndGetTheResult(new Callable<CharSequence>() {
            @Override 
            public CharSequence call() {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:findViewById
 
		return bitmap;
	} 
 
	public static <T extends View> T findView(Activity activity, int resId) {
		return (T) activity.findViewById(resId);
	} 
 
	public static <T extends View> T findView(View view, int resId) {
		return (T) view.findViewById(resId);
	} 
 
	public static <T extends Fragment> T findFragment(FragmentActivity activity, int resId) {
		return (T) activity.getSupportFragmentManager().findFragmentById(resId);
	} 
 
	public static <T extends Fragment> T findFragment(FragmentActivity activity, String tag) {
		return (T) activity.getSupportFragmentManager().findFragmentByTag(tag);
	} 
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:findViewById, getWindow, getTheme
 
		if (getParent() != null)
			throw new IllegalStateException("This SlidingMenu appears to already be attached");
 
		// get the window background 
		TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] {android.R.attr.windowBackground});
		int background = a.getResourceId(0, 0);
		a.recycle();
 
		switch (slideStyle) {
		case SLIDING_WINDOW:
			mActionbarOverlay = false;
			ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
			ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
			// save ActionBar themes that have transparent assets 
			decorChild.setBackgroundResource(background);
			decor.removeView(decorChild);
			decor.addView(this);
			setContent(decorChild);
			break; 

5
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Activity findViewById Questions & Answers:

Other Activity findViewById Examples

10:	        super.onCreate(savedInstanceState);
11:	        setContentView(R.layout.activity_main);
12:	        TextView view =  (TextView) findViewById(R.id.TextView02);
13:	        String s="";
14:	        for (int i=0; i < 500; i++) {

Read More

15:	    setContentView(R.layout.main);
16:	    // define the contextual action mode
17:	    View view = findViewById(R.id.myView);
18:	    view.setOnLongClickListener(new View.OnLongClickListener() {
19:	      // called when the user long-clicks on someView

Read More

22:	    super.onCreate(savedInstanceState);
23:	    setContentView(R.layout.main);
24:	    imageView = (ImageView) findViewById(R.id.result);
25:	  }
26:

Read More

18:	         * */
19:	        // Dashboard News feed button
20:	        Button btn_newsfeed = (Button) findViewById(R.id.btn_news_feed);
21:	        
22:	        // Dashboard Friends button
-
21:	        
22:	        // Dashboard Friends button
23:	        Button btn_friends = (Button) findViewById(R.id.btn_friends);
24:	        
25:	        // Dashboard Messages button
-
24:	        
25:	        // Dashboard Messages button
26:	        Button btn_messages = (Button) findViewById(R.id.btn_messages);
27:	        
28:	        // Dashboard Places button
-
27:	        
28:	        // Dashboard Places button
29:	        Button btn_places = (Button) findViewById(R.id.btn_places);
30:	        
31:	        // Dashboard Events button
-
30:	        
31:	        // Dashboard Events button
32:	        Button btn_events = (Button) findViewById(R.id.btn_events);
33:	        
34:	        // Dashboard Photos button
-
33:	        
34:	        // Dashboard Photos button
35:	        Button btn_photos = (Button) findViewById(R.id.btn_photos);
36:	        
37:	        /**

Read More

21:			setContentView(R.layout.main);
22:	
23:			Button btnStatus = (Button) findViewById(R.id.btn_check);
24:	
25:			// creating connection detector class instance

Read More

18:			setContentView(R.layout.activity_main);
19:	
20:			llStats = (LinearLayout) findViewById(R.id.llStats);
21:			txtPlayCount = (TextView) findViewById(R.id.txtNowPlaying);
22:			txtEarned = (TextView) findViewById(R.id.txtEarned);
-
19:	
20:			llStats = (LinearLayout) findViewById(R.id.llStats);
21:			txtPlayCount = (TextView) findViewById(R.id.txtNowPlaying);
22:			txtEarned = (TextView) findViewById(R.id.txtEarned);
23:	
-
20:			llStats = (LinearLayout) findViewById(R.id.llStats);
21:			txtPlayCount = (TextView) findViewById(R.id.txtNowPlaying);
22:			txtEarned = (TextView) findViewById(R.id.txtEarned);
23:	
24:			// layout background transparent

Read More

1:	ListView listView = (ListView) findViewById(R.id.listview);
2:	listView.setAdapter(adapter);
3:

Read More

1:	Button myButton = (Button) findViewById(R.id.my_button);
2:

Read More

26:	
27:	        // Must add the progress bar to the root of the layout
28:	        ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
29:	        root.addView(progressBar);
30:

Read More

findViewById Method Overview
Finds a view that was identified by the id attribute from the XML that was processed in onCreate(Bundle).
See Code Examples for other Android Activity Methods: