Re: [问题] 在Fragment做切换页时出错

楼主: passli   2014-06-12 12:55:45
改成这样试试看
private View initView(LayoutInflater inflater, ViewGroup container) {
View view = inflater.inflate
(R.layout.fragment_search, container, false);
imgbtn1=(ImageButton) view.findViewById(R.id.imageButton1);
imgbtn1.setOnClickListener(Listener);
}
return view;
}
※ 引述《kira5033 (吉良)》之铭言:
: 目前在做的是有侧边滑动选单能切换页,也想做分页
: 能用按钮切换页的功能,而侧边选单是套用别人做好的来使用,
: 他的分页都是用fragment做的,再来我想在其中一个分页中设定imagebutton,
: 让它可以连结其他分页A或B,我就参照工具书跟google来设定,
: 结果测试的时候就出问题了。
: 附上首页程式码
: https://gist.github.com/anonymous/9683d29144af026e22da
: 其中把这段删掉程式又正常了
: ImageButton imgbtn1;
: @Override
: public void onCreate(Bundle savedInstanceState)
: {
: // TODO Auto-generated method stub
: super.onCreate(savedInstanceState);
: imgbtn1=(ImageButton) getView().findViewById(R.id.imageButton1);
: imgbtn1.setOnClickListener(Listener);
: }
: private Button.OnClickListener Listener = new Button.OnClickListener(){
: @Override
: public void onClick(View v) {
: Intent intent=new Intent();
: switch(v.getId())
: {
: case R.id.imageButton1:
: intent.setClass(getActivity(),TestPage.class);
: getActivity().startActivity(intent);
: break;
: }
: }
: };
: 不知道是不是我搞错了写法,还请各位大大指教
: 谢谢
: 附上错误讯息
: https://gist.github.com/anonymous/9dbf59d7eef33c3b34cd
作者: kira5033 (吉良)   2014-06-12 21:21:00
感谢帮助 程式不会当掉了只是现在问题是转页失败 我的按钮没反应

Links booklink

Contact Us: admin [ a t ] ucptt.com