目前在做的是有側邊滑動選單能切換頁,也想做分頁
能用按鈕切換頁的功能,而側邊選單是套用別人做好的來使用,
他的分頁都是用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
作者: passli 2014-06-11 22:39:00
Fragment 是在onCreateView 裡面去inflate view出來
我把onCreate的東西丟進OnCeateView還是錯的說
imgbtn1=(ImageButton) view.findViewById(R.id.imageimgbtn1.setOnClickListener(Listener);這兩行放到你的initView裡面
NullPointerException你只要把FragmentSearch找就知道