如何修复错误错误:此片段内部类应该是静态的(com.example.UserSettingActivity.MyPreferenceFragment)[ValidFragment]

时间:2017-02-05 16:07:05

标签: android android-fragments inner-classes

我即将发布一个apk,但是当我尝试创建一个已签名的apk时,会出现错误:

Error: This fragment inner class should be static (com.example.UserSettingActivity.MyPreferenceFragment) [ValidFragment]

当我为手机构建应用时,它不会出现。发生了什么事?

以下是导致问题的代码:

public class UserSettingActivity extends PreferenceActivity {

    private Preference myPreference;
    MainActivity.MyCallBack callBack;

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
    }

    public class MyPreferenceFragment extends PreferenceFragment { // OFFENDING LINE
        @Override
        public void onCreate(final Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.preferences);

            myPreference = findPreference("reset");
            myPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                public boolean onPreferenceClick(Preference arg0) {
                    AlertDialog.Builder alertDialog = new AlertDialog.Builder(UserSettingActivity.this);
                    alertDialog.setMessage(R.string.deleteDB);
                    alertDialog.setCancelable(true);
                    alertDialog.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            final DBAdapter db = new DBAdapter(UserSettingActivity.this);
                            db.open();
                            db.resetDatabase();
                            callBack = MainActivity.mCallback;
                            callBack.refreshMainActivity();
                        }
                    });
                    alertDialog.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    alertDialog.show();
                    return false;
                }
            });
        }
    }

}

我不太清楚自己这个代码是做什么的,而且它一直都有效。除了我正在尝试创建一个签名的apk!我该如何解决这个问题?

我可以将其设为静态,但是当静态类使用周围的类时,我会遇到问题......

0 个答案:

没有答案