This is my code(Edited):
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);
}
}
}
In main.xml ,Here there is textview whose text style is needed to be changed.The previous problem restarting the application to take effect check box preference is not needed now. But problem is that when i uncheck the checkbox preference its not going to its default state.Y so? Can any help me whats wrong in code?