A.A
A.A

Reputation: 1148

How I can get ActionBarActivity in FragmentActivity?

How I can get ActionBarActivity from a Class that extends from FragmentActivity .

This is all of code :

public class StartActivity extends FragmentActivity {
    GetMetrics_Class metrics;
    ActionBarActivity activity;
    ImageView imgHeader;
    ImageView img_Setting_note;
    ImageView img_Calendar;
    ImageView img_Mail;
    ImageView img_Review_note;
    ImageView img_Help;
    ImageView img_Setting;
    LinearLayout LFooter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);

        activity = this;
        //get width & height mobile .
        metrics = new GetMetrics_Class(activity);
        initializeVars();
        //Padding Header
        HedaerSize();
        //Padding footer
        FooterSize_Pading();
        //Height layout
        FooterSize_Layout_Height();

        getSupportFragmentManager().addOnBackStackChangedListener(new OnBackStackChangedListener()
        {
            public void onBackStackChanged()
            {
                int backCount = getSupportFragmentManager().getBackStackEntryCount();
                if (backCount == 0)
                {
                    finish();
                }
            }
        });
        if (savedInstanceState == null)
        {
            getSupportFragmentManager().beginTransaction().add(R.id.main_container, new FirstPage()).addToBackStack(null).commit();
        }
    }

    private void initializeVars() {
        imgHeader = (ImageView) findViewById(R.id.imgHeader);
        img_Setting_note = (ImageView) findViewById(R.id.img_Setting_note);
        img_Calendar = (ImageView) findViewById(R.id.img_Calendar);
        img_Mail = (ImageView) findViewById(R.id.img_Mail);
        img_Review_note = (ImageView) findViewById(R.id.img_Review_note);
        img_Help = (ImageView) findViewById(R.id.img_Help);
        img_Setting = (ImageView) findViewById(R.id.img_Setting);
    }
    private void HedaerSize(){
        int PTopHeader = (54 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PBottomHeader = (60 * GetMetrics_Class.GMetrics_height()) / 1280;

        int PRightHeader = (249 * GetMetrics_Class.GMetrics_width()) / 800;
        int PLeftHeader = (248 * GetMetrics_Class.GMetrics_width()) / 800;

        imgHeader.setPadding(PLeftHeader, PTopHeader,PRightHeader , PBottomHeader);
    }
    private void FooterSize_Pading(){
        int PTopFooter_Setting_note = (32 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PBottomFooter_Setting_note = (24 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PRightFooter_Setting_note = (36 * GetMetrics_Class.GMetrics_width()) / 800;
        int PLeftFooter_Setting_note = (36 * GetMetrics_Class.GMetrics_width()) / 800;
        img_Setting_note.setPadding(PLeftFooter_Setting_note, PTopFooter_Setting_note,
                PRightFooter_Setting_note, PBottomFooter_Setting_note);

        int PTopFooter_Calendar = (38 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PBottomFooter_Calendar = (31 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PRightFooter_Calendar = (44 * GetMetrics_Class.GMetrics_width()) / 800;
        int PLeftFooter_Calendar = (39 * GetMetrics_Class.GMetrics_width()) / 800;
        img_Calendar.setPadding(PLeftFooter_Calendar, PTopFooter_Calendar,
                PRightFooter_Calendar, PBottomFooter_Calendar);


        int PTopFooter_Mail = (34 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PBottomFooter_Mail = (24 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PRightFooter_Mail = (30 * GetMetrics_Class.GMetrics_width()) / 800;
        int PLeftFooter_Mail = (30 * GetMetrics_Class.GMetrics_width()) / 800;
        img_Mail.setPadding(PLeftFooter_Mail, PTopFooter_Mail, PRightFooter_Mail, PBottomFooter_Mail);

        int PTopFooter_Review_note = (40 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PBottomFooter_Review_note = (33 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PRightFooter_Review_note = (25 * GetMetrics_Class.GMetrics_width()) / 800;
        int PLeftFooter_Review_note = (25 * GetMetrics_Class.GMetrics_width()) / 800;
        img_Review_note.setPadding(PLeftFooter_Review_note, PTopFooter_Review_note,
                PRightFooter_Review_note, PBottomFooter_Review_note);

        int PTopFooter_Help = (31 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PBottomFooter_Help = (24 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PRightFooter_Help = (28 * GetMetrics_Class.GMetrics_width()) / 800;
        int PLeftFooter_Help = (28 * GetMetrics_Class.GMetrics_width()) / 800;
        img_Help.setPadding(PLeftFooter_Help, PTopFooter_Help, PRightFooter_Help, PBottomFooter_Help);

        int PTopFooter_Setting = (31 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PBottomFooter_Setting = (17 * GetMetrics_Class.GMetrics_height()) / 1280;
        int PRightFooter_Setting = (30 * GetMetrics_Class.GMetrics_width()) / 800;
        int PLeftFooter_Setting = (30 * GetMetrics_Class.GMetrics_width()) / 800;
        img_Setting.setPadding(PLeftFooter_Setting, PTopFooter_Setting,
                PRightFooter_Setting, PBottomFooter_Setting);
    }

    public void FooterSize_Layout_Height(){
        LFooter = (LinearLayout) findViewById(R.id.LFooter);
        LFooter.getLayoutParams().height = (115 * GetMetrics_Class.GMetrics_height()) / 1280;
    }
}

Notice : Here activity = this; don't get me this.

Notice : I need that pass activity = this; to GetMetrics_Class(activity) for get width and height .

Upvotes: 0

Views: 138

Answers (2)

Terry
Terry

Reputation: 14897

ActionBarActivity already inherits (is a) FragmentActivity.

So all you need to do is to implement an instance of ActionBarActivity.

public class StartActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
    }
}

Upvotes: 3

CommonsWare
CommonsWare

Reputation: 1007369

How I can get ActionBarActivity from a Class that extends from FragmentActivity .

You can't. ActionBarActivity inherits from FragmentActivity. You cannot magically turn an instance of FragmentActivity into an instance of ActionBarActivity.

You are welcome to have StartActivity extend ActionBarActivity.

Upvotes: 1

Related Questions