在主 Activity 中使用可滑动的片段。
我无法弄清楚如何进行查找文件的调用,然后根据文件是否存在来调用setChecked(boolean)
Android Switch 上的方法。cb1
我目前进行了设置,以便在应用程序启动时显示一个弹出窗口并且用户单击确定,这会触发文件检查并设置检查操作。
澄清一下,我调用的所有操作都按预期工作,除非它位于onCreate()
.
如果它在 中onCreate()
,则 logcat 将显示 NullPointerException 由DeviceSetup.setup
第一行所在的任何一行引起setChecked(boolean)
。
MainActivity#onCreate()
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ChangeTheme.userchoice(this);
DeviceState.startup(this);
setContentView(R.layout.activity_main);
// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOffscreenPageLimit(3);
mViewPager.setCurrentItem(1);
}
DeviceState
班级:
public class DeviceState extends MainActivity {
public static void startup(final MainActivity activity) {
AlertDialog alertDialog = new AlertDialog.Builder(activity).create();
alertDialog.setTitle("Welcome");
alertDialog.setMessage("Select Ok to continue");
alertDialog.setButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Button startup = (Button) activity.findViewById(R.id.startup);
startup.performClick(); /* <<<THAT BUTTON TRIGGERS "SETUP" BELOW */
Rooted.rooted(activity);
}
});
alertDialog.show();
}
public static void setup(MainActivity activity) {
File file1 = new File("/system/app/somerandom.apk");
if (file1.exists()) {
cb1.setChecked(true);
} else {
cb1.setChecked(false);
}
}
Fragments
班级:
public class Fragments extends FragmentActivity {
public static class FragMods extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString("BUGFIX", "BUGFIX");
super.onSaveInstanceState(outState);
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(
R.layout.fragment_mods, container, false);
return rootView;
}
}
public static class FragExtras extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public FragExtras() {}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString("BUGFIX", "BUGFIX");
super.onSaveInstanceState(outState);
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View extrasView = inflater.inflate(
R.layout.fragment_extras, container, false);
return extrasView;
}
}
public static class FragCred extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public FragCred() {}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString("BUGFIX", "BUGFIX");
super.onSaveInstanceState(outState);
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View creditView = inflater.inflate(
R.layout.fragment_credit, container, false);
return creditView;
}
}
}