これは私のコードです(編集済み):
public class Main extends Activity
{
TextView txt;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b=(Button) findViewById(R.id.button1);
txt = (TextView) findViewById(R.id.textView1);
b.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent intent= new Intent(Main.this,Preference.class);
startActivity(intent);
}
});
}
public void onResume()
{
super.onResume();
Toast.makeText(this, "onResume", Toast.LENGTH_LONG).show();
SharedPreferences myPreference=PreferenceManager.getDefaultSharedPreferences(this);
boolean first=myPreference.getBoolean("first", true);
if(first)
{
Typeface font=Typeface.MONOSPACE;
txt.setTypeface(font);
}
}
}
main.xml には、テキスト スタイルを変更する必要がある textview があります。チェック ボックスの設定を有効にするためにアプリケーションを再起動するという以前の問題は、現在は必要ありません。しかし、問題は、チェックボックスの設定をオフにすると、デフォルトの状態にならないことです.Yそうですか?コードの何が問題なのか助けてもらえますか?