这是我的片段,但我想处理返回按钮时,按下我想执行一些行动。
public class StringName {
public TextView headlineSecond;
String headline;
public BusinessDetail() {
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_business_detail, container, false);
headline =getArguments().getString("headline");
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
headlineSecond = (TextView) view.findViewById(R.id.id_headline_second_business);
headlineSecond.setText(headline);
}
public boolean onBackPressed() {
Log.d("ashu","back button pressed");
return false;
}
}
2条答案
按热度按时间8hhllhi21#
尝试下面的代码来管理backpress:
ztigrdn82#
参考这篇文章:Android Fragment Handle back pressed
它涉及在KEY_BACK按下时监听。