Home onCreate in an extends baseActivity
Reply: 0

onCreate in an extends baseActivity

user3193
1#
user3193 Published in April 22, 2018, 6:50 am

BaseActivity

public abstract class BaseActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {

    protected BottomNavigationViewEx navigationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getContentViewId());

        navigationView = findViewById(R.id.bnve);
        navigationView.setOnNavigationItemSelectedListener(this);

        navigationView.enableAnimation(false);
        navigationView.enableShiftingMode(false);
        navigationView.enableItemShiftingMode(false);
        navigationView.setTextVisibility(true);
    }

    @Override
    protected void onStart() {
        super.onStart();
        updateNavigationBarState();
    }

    @Override
    public void onPause() {
        super.onPause();
        overridePendingTransition(0, 0);
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == R.id.item1) {
            Intent intent1 = new Intent(this, MainActivity.class);
            startActivity(intent1);
        } else if (item.getItemId() == R.id.item2) {
            Intent intent2 = new Intent(this, test2.class);
            startActivity(intent2);
        } else if (item.getItemId() == R.id.item3) {
            Intent intent3 = new Intent(this, test3.class);
            startActivity(intent3);
        } else if (item.getItemId() == R.id.item4) {
            Intent intent4 = new Intent(this, test4.class);
            startActivity(intent4);
        } else if (item.getItemId() == R.id.itemcen) {
            return false;
        }
        return true;
    }


    private void updateNavigationBarState(){
        int actionId = getNavigationMenuItemId();
        selectBottomNavigationBarItem(actionId);
    }

    void selectBottomNavigationBarItem(int itemId) {
        MenuItem item = navigationView.getMenu().findItem(itemId);
        item.setChecked(true);
    }

    abstract int getContentViewId();

    abstract int getNavigationMenuItemId();
}

MainActivity

public class MainActivity extends BaseActivity {

    @Override
    int getContentViewId() {
        return R.layout.activity_main;
    }

    @Override
    int getNavigationMenuItemId() {
        return R.id.item1;
       }

}

I have this BaseActivity and all the other activities are same as the MainActivity

My problem is that I don't know how to code inside each activity since when I add onCreate method inside the activity it doesn't work and the bottomNavigationBar gets missed up and stops working as expecting.

This is how I add the onCreate

public class MainActivity extends BaseActivity {

    @Override
    int getContentViewId() {
        return R.layout.activity_main;
    }

    @Override
    int getNavigationMenuItemId() {
        return R.id.item1;
    }

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

}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305765 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO