解决方案 »
- android注入.so时遇到error: undefined reference to 'dlopen'
- 如何 获得其他应用 的permission
- ndk真机调试的一个错误
- android下载源码如何知道branch的名称
- 如何实现类似TimePicker的数字输入控件?
- axis2协议下webservice返回多个return,如何通过ksoap分别读取?
- android 系统对话框背景色属性
- android 中的页面显示的分辨率
- android应用开发QQ群:70121071,欢迎大家踊跃加入讨论
- Android自动化测试工具MonkeyRunner输入参数问题
- ffmpeg 使用
- 关于被加密的sqlite数据库代码无法打开
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_a, container, false);
return view ;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
TextView textView1 = (TextView) getView().findViewById(R.id.textView1);
textView1.setText("改变");
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
TextView textView1 = (TextView) view.findViewById(R.id.textView1); //引用上面创建好的。就可以了,刚忘了修改
textView1.setText("改变");
}
用mView查找
private View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_a, container, false);
if (view == null) {
Log.i("FragmentA", " onCreateView:view is null");
} else {
Log.i("FragmentA", "onCreateView:view is NOOOOOOOOOOOOOOOOT null");
}
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (view == null) {
Log.i("FragmentA", " onActivityCreated:view is null");
} else {
Log.i("FragmentA", "onActivityCreated:view is NOOOOOOOOOOOOOOOOT null");
}
TextView textView1 = (TextView) view.findViewById(R.id.textView1);
if (textView1 == null) {
Log.i("FragmentA", " onActivityCreated:textView1 is null");
} else {
Log.i("FragmentA", "onActivityCreated:textView1 is NOOOOOOOOOOOOOOOOT null");
}
//textView1.setText("改变");
}
}
logcat:
06-04 16:56:26.953: D/ActivityThread(22471): setTargetHeapUtilization:0.25
06-04 16:56:26.953: D/ActivityThread(22471): setTargetHeapIdealFree:8388608
06-04 16:56:26.953: D/ActivityThread(22471): setTargetHeapConcurrentStart:2097152
06-04 16:56:27.314: W/IconCustomizer(22471): can't load transform_config.xml
06-04 16:56:27.344: I/FragmentA(22471): onCreateView:view is NOOOOOOOOOOOOOOOOT null
06-04 16:56:27.344: I/FragmentA(22471): onActivityCreated:view is NOOOOOOOOOOOOOOOOT null
06-04 16:56:27.344: I/FragmentA(22471): onActivityCreated:textView1 is null
06-04 16:56:27.404: I/Adreno200-EGL(22471): <qeglDrvAPI_eglInitialize:294>: EGL 1.4 QUALCOMM build: (CL3090659)
06-04 16:56:27.404: I/Adreno200-EGL(22471): Build Date: 09/03/13 Tue
06-04 16:56:27.404: I/Adreno200-EGL(22471): Local Branch:
06-04 16:56:27.404: I/Adreno200-EGL(22471): Remote Branch:
06-04 16:56:27.404: I/Adreno200-EGL(22471): Local Patches:
06-04 16:56:27.404: I/Adreno200-EGL(22471): Reconstruct Branch:
这样做。
private View view;
private TextView textView1 ;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_a, container, false);
if (view == null) {
Log.i("FragmentA", " onCreateView:view is null");
} else {
Log.i("FragmentA", "onCreateView:view is NOOOOOOOOOOOOOOOOT null");
}
textView1 = (TextView) view.findViewById(R.id.textView1);
return view;
}
这样就成功了,在FragmentA的onStart等方法中,getActivity().findViewById(R.id.textView1) 就能得到这个TextView。
直接继承 android.app.Fragment,就不行。也许是Android的bug吧。其实我是按照developer.android.com上的trainning的例子做的,那个例子是为了兼容android3.0以前的系统,继承了android.support.v4.app.Fragment,官方例子运行正常。
我的手机是Android4.1的,可以支持Fragment,所以我直接继承了adnroid.app.Fragment,结果就死活不成功。想不到是这个原因。谢谢各位。结贴。