これについてはすでにいくつかの質問がありますが、解決策が見つかりません。独自のサブクラスを使用してPreferenceFragment
設定を指定する LiveWallpaper があります。最もよく引用される解決策は、setContentView()
が before で呼び出されるようにすることですfindViewByID()
。レイアウトが指定されていないためsetContentView()
、まったく呼び出していません。PreferenceActivity.getPreferenceManager()
このアプリはもともと、レイアウトを使用せずに、およびなどの非推奨の方法を使用して設定を実装し、問題なく動作しました。を使用してコードを最新のものにしようとしていますPreferenceFragment
。
レイアウトを用意する必要はありますか? もしそうなら、本当に必要ない場合はどうすればよいですか?
または、ビューを取得/設定する別の方法はありますか?
public class SetPreferenceActivity extends Activity {
private CheckBox redCheckBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main); ???
redCheckBox = (CheckBox)findViewById(R.id.redCheckBox); // returns null
getFragmentManager().beginTransaction().replace(android.R.id.content, new LiveWallpaperPreferenceFragment()).commit();
}
}