I am using PreferenceFragment to get preferences from user. I have designed a simple preference file having only one EditPreference. I have created the following preferencefragement file
public class fragact extends PreferenceFragment
{
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.fragpref);
}
}
In my main activity i am trying to show the fragment at the click of a button.However the fragment comes transparent and is not very visible and the underlying screen is seen through it. why the fragment does not come proper. i created another activity and used it to show the fragment.it worked properly .but why can we show the fragment directly rather than showing through another activity in its oncreate and calling it through startActivity in class fragprefmain.
public class fragprefmain extends Activity
{
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.fragpref);
et=(EditText)findViewById(R.id.editText1);
}
public void showp(View v)
{
FragmentManager fm=getFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
ft.replace(android.R.id.content, new fragact());
ft.commit();
}
public void showval(View v)
{
SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(this);
et.setText(sp.getString("ekey", "no valued given"));
}