3 回答
TA贡献1776条经验 获得超12个赞
你可以试试这个..这会有所帮助
public class home extends Fragment {
private Button btn_dumge_login;
public home() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_home, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
btn_dumge_login = view.findViewById(R.id.dumgeLogin)
btn_dumge_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), TestActivity.class) ;
getActivity().startActivity(intent);
}
});
}
}
TA贡献1802条经验 获得超5个赞
View view = inflater.inflate(R.layout.your_layout_file, container, false);
view.findViewById(R.id.button_id).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
getContext().startActivity(new Intent(getContext(), YourNewActivity.class));
});
return view;
您可以在 onCreateView() 方法的片段“home”中使用此代码
TA贡献1783条经验 获得超4个赞
您应该首先选择要从中导航的视图,例如 ID 为 dugmeLogin 的按钮
那么你的代码应该是这样的
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_home, container, false);
Button loginButton = view.findViewById(R.id.dugmeLogin);
loginButton.setOnClickListener(v -> {
// You code goes here
});
return view;
}
这是你的 home.java
添加回答
举报