我想在用户点击重置按钮
后删除或重置值0这里是我正在使用的代码,但似乎不起作用..
我做错了什么,我无法弄清楚,..我也试过各种方式,使用谷歌搞清楚,但仍然卡住了。
sharedPreferences = getActivity().getPreferences(1);
sharedPreferences.edit().remove("ccs11").commit();
sharedPreferences.edit().remove("spinner_paneer").commit();
下面是我的片段,我正在尝试实施。
public PlanFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_gain, container, false);
sharedPreferences = getActivity().getPreferences(1);
String cp1s11=sharedPreferences.getString("cp111", "0");
String cf1s11=sharedPreferences.getString("cf111", "0");
String ccs11=sharedPreferences.getString("cc111", "0");
//Button
btnfinish=(Button)rootView.findViewById(R.id.finish_gain);
btnfinish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sharedPreferences = getActivity().getPreferences(1);
edt = sharedPreferences.edit();
edt.putString("ccs11", pro11.getText().toString());
edt.apply();
Intent intent = new Intent(getActivity(), MainActivity.class);
getActivity().startActivity(intent);
}
});
btnreset=(Button)rootView.findViewById(R.id.reset);
btnreset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sharedPreferences = getActivity().getPreferences(1);
sharedPreferences.edit().remove("ccs11").commit();
sharedPreferences.edit().remove("spinner_paneer").commit();
}
});
return rootView;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public void onDetach() {
super.onDetach();
}
}