在我的表单片段硬件"返回"按钮工作不正确。例如,当我打开片段并且当我没有开始输入时,我按下硬件"返回"按钮它的工作非常好。但是当我开始打字并打字后按下硬件"返回"按钮不起作用。
我的表单片段我正在使用OnResume()方法来处理后退按钮进程。
@Override
public void onResume() {
super.onResume();
getView().setFocusableInTouchMode(true);
getView().requestFocus();
getView().setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK){
//getView().clearFocus();
getActivity().getSupportFragmentManager().popBackStack();
return true;
}
return false;
}
});
}
答案 0 :(得分:0)
覆盖onBackPressed()
@Override
public void onBackPressed()
{
moveTaskToBack(true);
}
答案 1 :(得分:0)
EditText creditcatno= (EditText)view.findviewByid(R.id.ed1);
public void onResume(){super.onResume(); creditcatno1.setOnKeyListener(new View.OnKeyListener(){@Override public boolean onKey(View v,int keyCode,KeyEvent event){if(keyCode == KeyEvent.KEYCODE_BACK){// call previous Fragment here返回true;} return false; }}; 。getView()setFocusableInTouchMode(真); 。getView()requestFocus()方法; getView()。setOnKeyListener(new View.OnKeyListener(){@Override public boolean onKey(View v,int keyCode,KeyEvent event){if(event.getAction()== KeyEvent.ACTION_UP&& keyCode == KeyEvent。 KEYCODE_BACK){//回退按钮的点击监听器//Toast.makeText(getActivity()," Back press",Toast.LENGTH_SHORT).show(); getActivity()。getSupportFragmentManager() .popBackStack(); return true;} return false;}}); }
答案 2 :(得分:0)
制作一个静态字符串变量:
ggplot() +
geom_bar(aes(y = Beneficiaries, x = Age, fill = type),
data = sdi_data_2,
stat = "identity") +
theme_bw() +
scale_y_continuous(label = comma) +
scale_fill_manual(
name = "",
values = c(
"Injuries" = "orange2",
"Circulatory, Respiratory, Endocrine, and Neoplasms" =
"sandybrown",
"Nervous System" = "peachpuff",
"Intellectual Disability" = "skyblue2",
"Musculo-Skeletal" = "royalblue3",
[enter image description here][1] "Other and Unknown" =
"lightgoldenrod1",
"Other Mental Health" = "royalblue1"
),
breaks = c(
"Other and Unknown",
"Injuries",
"Circulatory, Respiratory, Endocrine, and Neoplasms",
"Nervous System",
"Musculo-Skeletal",
"Other Mental Health",
"Intellectual Disability"
)
)
打开片段时,将此变量值设置为片段名称:
public static String currentFragment = "";
现在使用MainActivity.currentFragment = "your fragment name";
中的onbackpress
方法:
MainActivity