我寫了下面的代碼2個不同的XML頁面:嘗試使用2個不同的按鍵
public class FragmentFirstPage extends Fragment implements OnClickListener{
View root;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle){
root = inflater.inflate(R.layout.fragment_page1, container, false);
Button bt = (Button) root.findViewById(R.id.button1);
bt.setOnClickListener(this);
Button mbt = (Button) root.findViewById(R.id.imageButton1);
mbt.setOnClickListener(new View.OnClickListener() {
final ViewPager viewPager = (ViewPager) getActivity().findViewById (R.id.activity_main_viewpager);
@Override
public void onClick (View v){
viewPager.setCurrentItem (viewPager.getCurrentItem() + 1); //or -1 to go previous
}
});
return root;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(getActivity(), SplashActivity.class);
getActivity().startActivity(myIntent);
}
當我運行它,它不顯示任何錯誤,但也不管用。它顯示一條錯誤消息,說不幸的應用程序已停止工作。我應該怎麼做才能獲得這個權利我的XML頁面有2個按鈕button1打開一個活動和imagebutton1顯示下一個片段。這是我想要實現的。
三江源爵士它的工作完美 – Anish688
沒問題,很高興爲您排憂解難。 – csmckelvey
確定一切正常,但當我嘗試添加聲音池時,它永遠不會播放曲目。 – Anish688