【发布时间】:2015-12-01 07:52:41
【问题描述】:
如果我从共享首选项中删除所有内容,我可以让我的按钮工作。我怎样才能让我的按钮工作并保持我的偏好?
我不确定我发布的代码是否正确。我很少发布任何东西。如果我做错了,请告诉我我需要做些什么来修复它。
public class FairgroveDirectory extends Fragment
{
ImageButton fairgrove_cell;
public FairgroveDirectory() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fairgrove_directory, container, false);
fairgrove_cell = (ImageButton) root.findViewById(R.id.fairgrove_cell);
fairgrove_cell.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Toast.makeText(getActivity(), "You Clicked the button!", Toast.LENGTH_LONG).show();
}
});
SharedPreferences fontSize =PreferenceManager.getDefaultSharedPreferences(getActivity());
// Get the font size option. We use "FONT_SIZE" as the key.
// Make sure to use this key when you set the value in SharedPreferences.
// We specify "Medium" as the default value, if it does not exist.
String fontSizePref = fontSize.getString("FONT_SIZE", "Small");
// Select the proper theme ID.
// These will correspond to your theme names as defined in themes.xml.
Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.FontSizeSmall);
if ("Medium".equals(fontSizePref)) {
contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.FontSizeMedium);
}
else if ("Large".equals(fontSizePref)) {
contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.FontSizeLarge);
}
else if ("XLarge".equals(fontSizePref)) {
contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.FontSizeXLarge);
}
// Set the theme for the activity.
// clone the inflater using the ContextThemeWrapper
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
// inflate the layout using the cloned inflater, not default inflater
return localInflater.inflate(R.layout.fairgrove_directory, container, false);
}
}
【问题讨论】:
-
返回根目录;用你的代码替换它