adt跟新到22.6.1后,创建android工程后mainactivity文件结构变了,找不到写在fragment中的控件 本帖最后由 u012745013 于 2014-03-28 12:20:08 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 api19上面没有注明这样的区别啊,为啥会找不到id了,,, 我还是在mainactivity中的oncreate方法中用findviewbyid方法,结果就报空指针异常,我不知道去哪里找了 你的意思你再if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()).commit(); }这句话后面findViewById会报错? 是的,我还是按照原来的习惯 button = (Button) this.findViewById(R.id.buttonzwb); textView = (TextView) this.findViewById(R.id.textView1); progressBar = (ProgressBar) this.findViewById(R.id.progressBar); editText = (EditText) this.findViewById(R.id.editText); // button.setOnClickListener(this); System.out.println(editText.getText().toString().trim()); 我前几天看api的时候,没有注意到4.4有声明这项改动的,,, 查了下资料,别人说要在 View rootView = inflater.inflate(R.layout.fragment_main, container, false);这里写 这是一个静态类,外面声明的里面不能用,里面 声明的外面也获取不到啊public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); return rootView; } } 恩,我也不知道为啥原理,待我再去研究下,你先把问题结局,在那里findViewById就行 看下这个帖子http://bbs.csdn.net/topics/390742254 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); TextView textView = (TextView) rootView .findViewById(R.id.section_label); textView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER))); 关于基于android的时间轴问题、大家来看看。 怎么判断手机屏幕是横屏的,还是竖屏的?全键盘手机大都是横屏的 SQLlite删除操作问题 监听短信广播 android中下拉列表框如何伸‘舌头’ 救火 选择Ophone的10个理由 viewpager嵌套viewpager滑动冲突 求助,聊天功能的问题 [android新手]在manifest里修改theme报错 怎么在非activity使用数据库 AcitivityGroup中Activity跳转出现闪屏 Java中如何通过反射获取 T 类型
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}这句话后面findViewById会报错?
textView = (TextView) this.findViewById(R.id.textView1);
progressBar = (ProgressBar) this.findViewById(R.id.progressBar);
editText = (EditText) this.findViewById(R.id.editText);
// button.setOnClickListener(this);
System.out.println(editText.getText().toString().trim());
false);这里写
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
TextView textView = (TextView) rootView
.findViewById(R.id.section_label);
textView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER)));