Fragment中通过button打开其他activity
我在应用的菜单设计上使用了Fragment,现在想在user界面通过一个button(setting)进入设置(SettingActivity),不过写了好几遍都不对。以...
我在应用的菜单设计上使用了Fragment,现在想在user界面通过一个button(setting)进入设置(SettingActivity),不过写了好几遍都不对。以下是现在的UserFragment.java,求大神直接帮我把代码加进去。
public class UserFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.user, null);
ImageView left = (ImageView) view.findViewById(R.id.iv_user_left);
left.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
((MainActivity) getActivity()).showLeft();
}
});
return view;
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
} 展开
public class UserFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.user, null);
ImageView left = (ImageView) view.findViewById(R.id.iv_user_left);
left.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
((MainActivity) getActivity()).showLeft();
}
});
return view;
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
} 展开
1个回答
2014-01-24
展开全部
Button button = view.findViewById(xxx);
button.setOnClickListener(new View.OnClickListener(
onClick(View view){
startActivity(new Intent(getActivity(), SettingActivity.class));
}
));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询