2

My custom FragmentSettings() extends android.preference.PreferenceFragment and I simply add it in my activity.

I want to inflate (add) as well the layout.logo which has gravity:bottom. However with my code the inflated layout.logo is not visible. I guess because I use inflate() with getFragmentManager()? How can I correctly add a layout in this case?

public class ActivitySettings  extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {   
        super.onCreate(savedInstanceState);
        FragmentSettings details = new FragmentSettings();
        details.setArguments(getIntent().getExtras());
        getFragmentManager().beginTransaction().add(android.R.id.content, details).commit();

        getLayoutInflater().inflate(R.layout.logo, null );
    }


}

PS: R.layout.logo is an ImageView.

Diolor
  • 13,181
  • 30
  • 111
  • 179

1 Answers1

1

Try this

public void onCreate(Bundle savedInstanceState) {   
    super.onCreate(savedInstanceState);
    FragmentSettings details = new FragmentSettings();
    details.setArguments(getIntent().getExtras());
    getFragmentManager().beginTransaction().add(android.R.id.content, details).commit();

    LayoutInflater inflater = LayoutInflater.from(context);
    View view =inflater.inflate(R.layout.logo, null);
    // may be logo is a layout file, if not then put your layout file which contain an ImageView
   ImageView imageView = (ImageView)view.findViewById(R.id.imageView1);
}

but you said that R.layout.logo in an ImageView . you know, ImageView has an id and you will find it from R.id.(your ImageView's id ) hear. just i assume that imageView1 is and id of your ImageView.

Tanim reja
  • 2,120
  • 1
  • 16
  • 23
  • Thanks for replying. Firstly the ImageView is going to be the same in all cases so it's fine. Secondly what is (/how do you declare the variable) `context` in your answer? I tried `LayoutInflater.from(getBaseContext());` without success. – Diolor Feb 20 '14 at 12:19
  • Context context; is global variable . you can declare it in your activity class before onCreate() . – Tanim reja Feb 20 '14 at 12:46