@SuppressWarnings("unchecked")
public <T extends Fragment> T getFragment(int id) {
T result = (T)getFragmentManager().findFragmentById(id);
if (result == null) {
throw new IllegalArgumentException("fragment 0x" + Integer.toHexString(id)
+ " doesn't exist");
}
return result;
} /**
* Convenient version of {@link #findViewById(int)}, which throws
* an exception if the view doesn't exist.
*/
@SuppressWarnings("unchecked")
public <T extends View> T getView(int id) {
T result = (T)findViewById(id);
if (result == null) {
throw new IllegalArgumentException("view 0x" + Integer.toHexString(id)
+ " doesn't exist");
}
return result;
}

android通过泛型获取控件或视图的更多相关文章

  1. android 下动态获取控件的id

    有时候我们需要动态的取得一个一个控件的id,然后进行操作,经过在网上查找,找到了一下方法getResources().getIdentifier("textView01", &qu ...

  2. Android自动化测试中AccessibilityService获取控件信息(2)-三种方式对比

    Android自动化测试中AccessibilityService获取控件信息(2)-三种方式对比   上一篇文章: Android自动化测试中AccessibilityService获取控件信息(1 ...

  3. Android自动化测试中AccessibilityService获取控件信息(1)

    Android自动化测试中AccessibilityService获取控件信息(1) 分类: android自动化测试2014-03-24 15:31 3455人阅读 评论(16) 收藏 举报 and ...

  4. 获取Android屏幕尺寸、控件尺寸、状态栏/通知栏高度、导航栏高度

    1.获取Android屏幕尺寸 我们能够通过getSize()方法获得屏幕的尺寸 Display display = getWindowManager().getDefaultDisplay(); P ...

  5. android 获取屏幕的高度和宽度、获取控件在屏幕中的位置、获取屏幕中控件的高度和宽度

    (一)获取屏幕的高度和宽度 有两种方法: 方法1: WindowManager wm = (WindowManager) getContext().getSystemService(Context.W ...

  6. 从零开始学android开发-获取控件

    mBtnNews = (Button)findViewById(R.id.btn_news);//获取控件

  7. android获取屏幕宽高与获取控件宽高

    获取屏幕宽高 // 获取屏幕宽高(方法1) int screenWidth = getWindowManager().getDefaultDisplay().getWidth(); // 屏幕宽(像素 ...

  8. android 获取屏幕宽高 和 获取控件坐标

    一.获取屏幕宽高: (1). WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE); int width ...

  9. 【Android】获取控件的宽和高

    有时候我们须要在Activity的时候获取控件的宽和高来做一些操作,以下介绍三种获取宽和高的方式: 1. onWindowFocusChanged @Override public void onWi ...

随机推荐

  1. [Bootstrap] 1. container & container-fluid

    Container: 居中 <!DOCTYPE html> <html> <head> <title>Blasting Off With Bootstr ...

  2. Views

    Views Views are the visual side of the Nova, they are the HTML output of the pages. Views can be loc ...

  3. Fixflow引擎解析(三)(模型) - 创建EMF模型来读写XML文件

    Fixflow引擎解析(四)(模型) - 通过EMF扩展BPMN2.0元素 Fixflow引擎解析(三)(模型) - 创建EMF模型来读写XML文件 Fixflow引擎解析(二)(模型) - BPMN ...

  4. Objective-C中NSArray和NSMutableArray是如何使用的?

    Objective-C的数组比C++,Java的数组强大在于,NSArray保存的对象可以是不同的对象.但只能保存对象,int ,char,double等基本数据类型不能直接保存,需要通过转换成对象才 ...

  5. C++第五章函数

    书上的点: 这次直接写写画画了,遇到的bug也就直接敲了,忘记记录了,好在都在书上,所以勾画一下,提一下.发现每一章后面的小结,都蛮有意思的.可以抄一遍. 1.返回值的函数成为返回值函数(value- ...

  6. mysql copy表或表数据常用的语句整理汇总

    mysql copy表或表数据常用的语句整理汇总. 假如我们有以下这样一个表: id username password ----------------------------------- 1 a ...

  7. Python(2.7.6) 函数对象与闭包

    在 Python 中,一切皆对象.函数也是对象,它可以赋值给其他变量,也可以当作参数传递. lambda 表达式可以创建函数对象,在 Python 中,lambda 表达式的函数体只能有唯一的一条语句 ...

  8. C#开发微信门户及应用-使用地理位置扩展相关应用

    C#开发微信门户及应用-使用地理位置扩展相关应用 我们知道,地理位置信息可以用来做很多相关的应用,除了我们可以知道用户所在的位置,还可以关联出一些地理位置的应用,如天气,热映影片,附近景点,附近影院, ...

  9. ###《Machine Learning》by Andrew NG

    点击查看Evernote原文. #@author: gr #@date: 2014-10-17 #@email: forgerui@gmail.com Fundamental 一. 矩阵的迹.秩 矩阵 ...

  10. ###《Effective STL》--Chapter3

    点击查看Evernote原文. #@author: gr #@date: 2014-09-13 #@email: forgerui@gmail.com Chapter3 关联容器 Topic 22: ...